Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MathTex Font error #5208

Closed
tritemio opened this issue Oct 8, 2015 · 10 comments
Closed

MathTex Font error #5208

tritemio opened this issue Oct 8, 2015 · 10 comments
Milestone

Comments

@tritemio
Copy link

tritemio commented Oct 8, 2015

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

The plotting code is something like this:

lt, = plot(tt, res.eval(x=tt))
plot(t, Ratio, 'o', color=lt.get_color())
v = 0
for resG in resultsGauss:
    lf, = plot(tt, resG.eval(x=tt))
    plt.text(8.5, 0.7 - v, r"$\tau = %.2f s$" % resG.values['tau'], fontsize=24)
    plt.text(3, 0.7 - v, resG.model.func.__doc__, fontsize=24)
    v += 0.2
plot(t, RatioGauss, 'o', color=bpl.red)

And when it succeeds it generates a plot like this:

download

I'll update the issue if I can create a standalone example.

xref: maybe related to #3086

@mdboom
Copy link
Member

mdboom commented Oct 8, 2015

Have you tried deleting the font cache in ~/.matplotlib?

@tacaswell tacaswell modified the milestone: next bug fix release (2.0.1) Oct 8, 2015
@lucasb-eyer
Copy link

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

@lucasb-eyer
Copy link

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.

@jenshnielsen
Copy link
Member

This is likely resolved by #5295 which will be in matplotlib 2.0

@zhuoqiang
Copy link

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 resources
plt.close(fig)

@mfouesneau
Copy link

Same bug using Jupyter notebook. Does not crash systematically.

@jaketmp
Copy link

jaketmp commented Feb 16, 2017

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.

macOS
python 3.5.2 (Anaconda)
matplotlib 1.5.1
seaborn 0.7.1

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@anntzer
Copy link
Contributor

anntzer commented Jan 14, 2018

Likely closed by #5295 (there is no report using mpl 2.0) so closing, but please request a reopen if not.

@anntzer anntzer closed this as completed Jan 14, 2018
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
@HaseebTariq7
Copy link

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?

@jklymak
Copy link
Member

jklymak commented Dec 21, 2018

1.5.0rc3 is quite old. Do you have this issue on a more modern Matplotlib?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests