Skip to content

MathTex Font error #5208

Closed
Closed

Description

@tritemio

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

Activity

  1. mdboom commented on Oct 8, 2015

    @mdboom
    Member

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

  2. modified the milestone: on Oct 8, 2015
  3. lucasb-eyer commented on Jan 16, 2016

    @lucasb-eyer

    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
    
  4. lucasb-eyer commented on Jan 16, 2016

    @lucasb-eyer

    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.

  5. jenshnielsen commented on Jan 16, 2016

    @jenshnielsen
    Member

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

  6. zhuoqiang commented on Apr 17, 2016

    @zhuoqiang

    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)
  7. mfouesneau commented on Jul 4, 2016

    @mfouesneau

    Same bug using Jupyter notebook. Does not crash systematically.

  8. jaketmp commented on Feb 16, 2017

    @jaketmp

    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

  9. modified the milestones: , on May 3, 2017
  10. modified the milestones: , on Oct 9, 2017
  11. anntzer commented on Jan 14, 2018

    @anntzer
    Contributor

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

  12. modified the milestones: , v2.2.0 on Feb 12, 2018
  13. HaseebTariq7 commented on Dec 21, 2018

    @HaseebTariq7

    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?

  14. jklymak commented on Dec 21, 2018

    @jklymak
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions