You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Matplotlib 1.5.1rc1 (from conda repo)
seaborn 0.6
Anaconda
python 3.4
notebook 4.0.5
Mac OS X
backend inline
Plotting a figure with a bunch of mathtex formulas results in an error. Re-executing the same cell many times I get the error most of the time and the correct plot sometimes.
The stack trace is very long and termitates with:
/Users/anto/anaconda/envs/py3/lib/python3.4/site-packages/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
567
568 filename = findfont(default_font_prop)
--> 569 default_font = self.CachedFont(FT2Font(filename))
570 self._fonts['default'] = default_font
571 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
I have the same issue seemingly at random whenever "complex" text is involved.
Clearing the cache (in ~/.cache/matplotlib on linux) doesn't help.
This behavior is the same for me: "Re-executing the same cell many times I get the error most of the time and the correct plot sometimes." except that I don't re-execute the cell, but re-display inside a loop using IPython's clear_output and display functions.
Note that if I stop the cell while this happens, then any other plotting which involves "complex" text will fail. For example, plt.plot([1,2,3]) will work, but plt.plot([1,2,3]) ; plt.yscale('log') will fail, presumably due to the exponent in the axis-label text in the latter case.
Here's the full, long backtrace:
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x7f16a56a2048> (for post_execute):
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/pyplot.py in post_execute()
145 def post_execute():
146 if matplotlib.is_interactive():
--> 147 draw_all()
148
149 # IPython >= 2
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/_pylab_helpers.py in draw_all(cls, force)
148 for f_mgr in cls.get_all_fig_managers():
149 if force or f_mgr.canvas.figure.stale:
--> 150 f_mgr.canvas.draw_idle()
151
152 atexit.register(Gcf.destroy_all)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2024 if not self._is_idle_drawing:
2025 with self._idle_draw_cntx():
-> 2026 self.draw(*args, **kwargs)
2027
2028 def draw_cursor(self, event):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in draw(self)
472
473 try:
--> 474 self.figure.draw(self.renderer)
475 finally:
476 RendererAgg.lock.release()
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/figure.py in draw(self, renderer)
1131 dsu.sort(key=itemgetter(0))
1132 for zorder, a, func, args in dsu:
-> 1133 func(*args)
1134
1135 renderer.close_group('figure')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2302
2303 for zorder, a in dsu:
-> 2304 a.draw(renderer)
2305
2306 renderer.close_group('axes')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1106 ticks_to_draw = self._update_ticks(renderer)
1107 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1108 renderer)
1109
1110 for tick in ticks_to_draw:
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1056 for tick in ticks:
1057 if tick.label1On and tick.label1.get_visible():
-> 1058 extent = tick.label1.get_window_extent(renderer)
1059 ticklabelBoxes.append(extent)
1060 if tick.label2On and tick.label2.get_visible():
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in get_window_extent(self, renderer, dpi)
959 raise RuntimeError('Cannot get window extent w/o renderer')
960
--> 961 bbox, info, descent = self._get_layout(self._renderer)
962 x, y = self.get_unitless_position()
963 x, y = self.get_transform().transform_point((x, y))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in _get_layout(self, renderer)
359 w, h, d = renderer.get_text_width_height_descent(clean_line,
360 self._fontproperties,
--> 361 ismath=ismath)
362 else:
363 w, h, d = 0, 0, 0
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
232 if ismath:
233 ox, oy, width, height, descent, fonts, used_characters = \
--> 234 self.mathtext_parser.parse(s, self.dpi, prop)
235 return width, height, descent
236
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in parse(self, s, dpi, prop)
3103 fontset_class = self._font_type_mapping.get(fontset.lower())
3104 if fontset_class is not None:
-> 3105 font_output = fontset_class(prop, backend)
3106 else:
3107 raise ValueError(
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
678
679 def __init__(self, *args, **kwargs):
--> 680 self._stix_fallback = StixFonts(*args, **kwargs)
681
682 TruetypeFonts.__init__(self, *args, **kwargs)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
912
913 def __init__(self, *args, **kwargs):
--> 914 TruetypeFonts.__init__(self, *args, **kwargs)
915 self.fontmap = {}
916 for key, name in six.iteritems(self._fontmap):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/formatters.py in __call__(self, obj)
335 pass
336 else:
--> 337 return printer(obj)
338 # Finally look for special method names
339 method = _safe_get_formatter_method(obj, self.print_method)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
205
206 if 'png' in formats:
--> 207 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
208 if 'retina' in formats or 'png2x' in formats:
209 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
115
116 bytes_io = BytesIO()
--> 117 fig.canvas.print_figure(bytes_io, **kw)
118 data = bytes_io.getvalue()
119 if fmt == 'svg':
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2176 orientation=orientation,
2177 dryrun=True,
-> 2178 **kwargs)
2179 renderer = self.figure._cachedRenderer
2180 bbox_inches = self.figure.get_tightbbox(renderer)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
525
526 def print_png(self, filename_or_obj, *args, **kwargs):
--> 527 FigureCanvasAgg.draw(self)
528 renderer = self.get_renderer()
529 original_dpi = renderer.dpi
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in draw(self)
472
473 try:
--> 474 self.figure.draw(self.renderer)
475 finally:
476 RendererAgg.lock.release()
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/figure.py in draw(self, renderer)
1131 dsu.sort(key=itemgetter(0))
1132 for zorder, a, func, args in dsu:
-> 1133 func(*args)
1134
1135 renderer.close_group('figure')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2302
2303 for zorder, a in dsu:
-> 2304 a.draw(renderer)
2305
2306 renderer.close_group('axes')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1106 ticks_to_draw = self._update_ticks(renderer)
1107 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1108 renderer)
1109
1110 for tick in ticks_to_draw:
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1056 for tick in ticks:
1057 if tick.label1On and tick.label1.get_visible():
-> 1058 extent = tick.label1.get_window_extent(renderer)
1059 ticklabelBoxes.append(extent)
1060 if tick.label2On and tick.label2.get_visible():
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in get_window_extent(self, renderer, dpi)
959 raise RuntimeError('Cannot get window extent w/o renderer')
960
--> 961 bbox, info, descent = self._get_layout(self._renderer)
962 x, y = self.get_unitless_position()
963 x, y = self.get_transform().transform_point((x, y))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in _get_layout(self, renderer)
359 w, h, d = renderer.get_text_width_height_descent(clean_line,
360 self._fontproperties,
--> 361 ismath=ismath)
362 else:
363 w, h, d = 0, 0, 0
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
232 if ismath:
233 ox, oy, width, height, descent, fonts, used_characters = \
--> 234 self.mathtext_parser.parse(s, self.dpi, prop)
235 return width, height, descent
236
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in parse(self, s, dpi, prop)
3103 fontset_class = self._font_type_mapping.get(fontset.lower())
3104 if fontset_class is not None:
-> 3105 font_output = fontset_class(prop, backend)
3106 else:
3107 raise ValueError(
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
678
679 def __init__(self, *args, **kwargs):
--> 680 self._stix_fallback = StixFonts(*args, **kwargs)
681
682 TruetypeFonts.__init__(self, *args, **kwargs)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
912
913 def __init__(self, *args, **kwargs):
--> 914 TruetypeFonts.__init__(self, *args, **kwargs)
915 self.fontmap = {}
916 for key, name in six.iteritems(self._fontmap):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
I believe I found the cause, but not the origin, of the error: Too many open files.
Once this error starts occurring, many other operations which involve files (even import) will fail with Too many open files. Doing import gc ; gc.collect() takes a long time, returns a large number, and after that, plotting works!
So my guess is that something somewhere during plotting opens a file without closing it. It may be anything, probably grepping matplotlib's code using some pattern looking for occurrences of open without with on the same line may help finding the culprit.
So a workaround until someone finds and fixes the offending open in matplotlib would be to call import gc ; gc.collect() right before your plotting code.
I have encounter exactly the same issue in matplotlib v1.5 under Mac OS X
/Some/Path/To/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
It seems I have plotted too many figures but not had them released.
Close the figure after plot fix this issue:
fig, (ax1, ax2) =plt.subplots(2, sharex=True, figsize=(width, 10))
# some plot with the ax# ...# when done plot, close the fig to release resourcesplt.close(fig)
Also seeing this idiosyncratically when saving plots as pngs:
.../anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
<matplotlib.figure.Figure at 0x20c87be48>
Only seems to occur when repeatedly calling the same plot with differing arguments, removing format=figureFormat from the call to plt.savefig() seems to mean we don't see the crash.
I have the same issue seemingly at random whenever "complex" text is involved.
Clearing the cache (in ~/.cache/matplotlib on linux) doesn't help.
This behavior is the same for me: "Re-executing the same cell many times I get the error most of the time and the correct plot sometimes." except that I don't re-execute the cell, but re-display inside a loop using IPython's clear_output and display functions.
Note that if I stop the cell while this happens, then any other plotting which involves "complex" text will fail. For example, plt.plot([1,2,3]) will work, but plt.plot([1,2,3]) ; plt.yscale('log') will fail, presumably due to the exponent in the axis-label text in the latter case.
Here's the full, long backtrace:
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x7f16a56a2048> (for post_execute):
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/pyplot.py in post_execute()
145 def post_execute():
146 if matplotlib.is_interactive():
--> 147 draw_all()
148
149 # IPython >= 2
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/_pylab_helpers.py in draw_all(cls, force)
148 for f_mgr in cls.get_all_fig_managers():
149 if force or f_mgr.canvas.figure.stale:
--> 150 f_mgr.canvas.draw_idle()
151
152 atexit.register(Gcf.destroy_all)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2024 if not self._is_idle_drawing:
2025 with self._idle_draw_cntx():
-> 2026 self.draw(*args, **kwargs)
2027
2028 def draw_cursor(self, event):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in draw(self)
472
473 try:
--> 474 self.figure.draw(self.renderer)
475 finally:
476 RendererAgg.lock.release()
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/figure.py in draw(self, renderer)
1131 dsu.sort(key=itemgetter(0))
1132 for zorder, a, func, args in dsu:
-> 1133 func(*args)
1134
1135 renderer.close_group('figure')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2302
2303 for zorder, a in dsu:
-> 2304 a.draw(renderer)
2305
2306 renderer.close_group('axes')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1106 ticks_to_draw = self._update_ticks(renderer)
1107 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1108 renderer)
1109
1110 for tick in ticks_to_draw:
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1056 for tick in ticks:
1057 if tick.label1On and tick.label1.get_visible():
-> 1058 extent = tick.label1.get_window_extent(renderer)
1059 ticklabelBoxes.append(extent)
1060 if tick.label2On and tick.label2.get_visible():
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in get_window_extent(self, renderer, dpi)
959 raise RuntimeError('Cannot get window extent w/o renderer')
960
--> 961 bbox, info, descent = self._get_layout(self._renderer)
962 x, y = self.get_unitless_position()
963 x, y = self.get_transform().transform_point((x, y))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in _get_layout(self, renderer)
359 w, h, d = renderer.get_text_width_height_descent(clean_line,
360 self._fontproperties,
--> 361 ismath=ismath)
362 else:
363 w, h, d = 0, 0, 0
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
232 if ismath:
233 ox, oy, width, height, descent, fonts, used_characters = \
--> 234 self.mathtext_parser.parse(s, self.dpi, prop)
235 return width, height, descent
236
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in parse(self, s, dpi, prop)
3103 fontset_class = self._font_type_mapping.get(fontset.lower())
3104 if fontset_class is not None:
-> 3105 font_output = fontset_class(prop, backend)
3106 else:
3107 raise ValueError(
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
678
679 def __init__(self, *args, **kwargs):
--> 680 self._stix_fallback = StixFonts(*args, **kwargs)
681
682 TruetypeFonts.__init__(self, *args, **kwargs)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
912
913 def __init__(self, *args, **kwargs):
--> 914 TruetypeFonts.__init__(self, *args, **kwargs)
915 self.fontmap = {}
916 for key, name in six.iteritems(self._fontmap):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/formatters.py in __call__(self, obj)
335 pass
336 else:
--> 337 return printer(obj)
338 # Finally look for special method names
339 method = _safe_get_formatter_method(obj, self.print_method)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
205
206 if 'png' in formats:
--> 207 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
208 if 'retina' in formats or 'png2x' in formats:
209 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
115
116 bytes_io = BytesIO()
--> 117 fig.canvas.print_figure(bytes_io, **kw)
118 data = bytes_io.getvalue()
119 if fmt == 'svg':
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2176 orientation=orientation,
2177 dryrun=True,
-> 2178 **kwargs)
2179 renderer = self.figure._cachedRenderer
2180 bbox_inches = self.figure.get_tightbbox(renderer)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
525
526 def print_png(self, filename_or_obj, *args, **kwargs):
--> 527 FigureCanvasAgg.draw(self)
528 renderer = self.get_renderer()
529 original_dpi = renderer.dpi
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in draw(self)
472
473 try:
--> 474 self.figure.draw(self.renderer)
475 finally:
476 RendererAgg.lock.release()
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/figure.py in draw(self, renderer)
1131 dsu.sort(key=itemgetter(0))
1132 for zorder, a, func, args in dsu:
-> 1133 func(*args)
1134
1135 renderer.close_group('figure')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2302
2303 for zorder, a in dsu:
-> 2304 a.draw(renderer)
2305
2306 renderer.close_group('axes')
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1106 ticks_to_draw = self._update_ticks(renderer)
1107 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1108 renderer)
1109
1110 for tick in ticks_to_draw:
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1056 for tick in ticks:
1057 if tick.label1On and tick.label1.get_visible():
-> 1058 extent = tick.label1.get_window_extent(renderer)
1059 ticklabelBoxes.append(extent)
1060 if tick.label2On and tick.label2.get_visible():
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in get_window_extent(self, renderer, dpi)
959 raise RuntimeError('Cannot get window extent w/o renderer')
960
--> 961 bbox, info, descent = self._get_layout(self._renderer)
962 x, y = self.get_unitless_position()
963 x, y = self.get_transform().transform_point((x, y))
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/text.py in _get_layout(self, renderer)
359 w, h, d = renderer.get_text_width_height_descent(clean_line,
360 self._fontproperties,
--> 361 ismath=ismath)
362 else:
363 w, h, d = 0, 0, 0
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
232 if ismath:
233 ox, oy, width, height, descent, fonts, used_characters = \
--> 234 self.mathtext_parser.parse(s, self.dpi, prop)
235 return width, height, descent
236
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in parse(self, s, dpi, prop)
3103 fontset_class = self._font_type_mapping.get(fontset.lower())
3104 if fontset_class is not None:
-> 3105 font_output = fontset_class(prop, backend)
3106 else:
3107 raise ValueError(
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
678
679 def __init__(self, *args, **kwargs):
--> 680 self._stix_fallback = StixFonts(*args, **kwargs)
681
682 TruetypeFonts.__init__(self, *args, **kwargs)
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, *args, **kwargs)
912
913 def __init__(self, *args, **kwargs):
--> 914 TruetypeFonts.__init__(self, *args, **kwargs)
915 self.fontmap = {}
916 for key, name in six.iteritems(self._fontmap):
/home.local/lucas/sci-env3.4/lib/python3.4/site-packages/matplotlib-1.5.0rc3-py3.4-linux-x86_64.egg/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)
564
565 filename = findfont(default_font_prop)
--> 566 default_font = self.CachedFont(FT2Font(filename))
567 self._fonts['default'] = default_font
568 self._fonts['regular'] = default_font
TypeError: First argument must be a path or file object reading bytes
I am getting the same issue using jupyter notebook, so what's the solution is?
Activity
mdboom commentedon Oct 8, 2015
Have you tried deleting the font cache in ~/.matplotlib?
lucasb-eyer commentedon Jan 16, 2016
I have the same issue seemingly at random whenever "complex" text is involved.
Clearing the cache (in
~/.cache/matplotlibon linux) doesn't help.This behavior is the same for me: "Re-executing the same cell many times I get the error most of the time and the correct plot sometimes." except that I don't re-execute the cell, but re-display inside a loop using IPython's
clear_outputanddisplayfunctions.Note that if I stop the cell while this happens, then any other plotting which involves "complex" text will fail. For example,
plt.plot([1,2,3])will work, butplt.plot([1,2,3]) ; plt.yscale('log')will fail, presumably due to the exponent in the axis-label text in the latter case.Here's the full, long backtrace:
lucasb-eyer commentedon Jan 16, 2016
I believe I found the cause, but not the origin, of the error:
Too many open files.Once this error starts occurring, many other operations which involve files (even
import) will fail withToo many open files. Doingimport gc ; gc.collect()takes a long time, returns a large number, and after that, plotting works!So my guess is that something somewhere during plotting opens a file without closing it. It may be anything, probably grepping matplotlib's code using some pattern looking for occurrences of
openwithoutwithon the same line may help finding the culprit.So a workaround until someone finds and fixes the offending
openin matplotlib would be to callimport gc ; gc.collect()right before your plotting code.jenshnielsen commentedon Jan 16, 2016
This is likely resolved by #5295 which will be in matplotlib 2.0
zhuoqiang commentedon Apr 17, 2016
I have encounter exactly the same issue in matplotlib v1.5 under Mac OS X
It seems I have plotted too many figures but not had them released.
Close the figure after plot fix this issue:
mfouesneau commentedon Jul 4, 2016
Same bug using Jupyter notebook. Does not crash systematically.
jaketmp commentedon Feb 16, 2017
Also seeing this idiosyncratically when saving plots as pngs:
Only seems to occur when repeatedly calling the same plot with differing arguments, removing
format=figureFormatfrom the call toplt.savefig()seems to mean we don't see the crash.macOS
python 3.5.2 (Anaconda)
matplotlib 1.5.1
seaborn 0.7.1
anntzer commentedon Jan 14, 2018
Likely closed by #5295 (there is no report using mpl 2.0) so closing, but please request a reopen if not.
HaseebTariq7 commentedon Dec 21, 2018
I am getting the same issue using jupyter notebook, so what's the solution is?
jklymak commentedon Dec 21, 2018
1.5.0rc3 is quite old. Do you have this issue on a more modern Matplotlib?