Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In FT2Font: Can not load face

I am trying to plot a bar. But it shows Runtime error, and shows In FT2Font: Can not load face. at the Botton. I have tried uninstall and install it again. And tried another method, but still can not work. I think the code is right, because I successfully run it on a windows laptop. And my jupyter notebook is for Mac python 2.7.

The code is as following:

import numpy as np
import pandas as pd
obj = pd.Series([4, 7, -5, 3])
print type(obj)
obj
%matplotlib inline
obj.plot(kind = 'bar', figsize=[5,4])

But it shows some error :

<matplotlib.axes._subplots.AxesSubplot at 0x1114e69d0>
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/anaconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    332                 pass
    333             else:
--> 334                 return printer(obj)
    335             # Finally look for special method names
    336             method = get_real_method(obj, self.print_method)

/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
    238 
    239     if 'png' in formats:
--> 240         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    241     if 'retina' in formats or 'png2x' in formats:
    242         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    122 
    123     bytes_io = BytesIO()
--> 124     fig.canvas.print_figure(bytes_io, **kw)
    125     data = bytes_io.getvalue()
    126     if fmt == 'svg':

/anaconda2/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2206                     orientation=orientation,
   2207                     dryrun=True,
-> 2208                     **kwargs)
   2209                 renderer = self.figure._cachedRenderer
   2210                 bbox_inches = self.figure.get_tightbbox(renderer)

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    505 
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--> 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
    428             if toolbar:
    429                 toolbar.set_cursor(cursors.WAIT)
--> 430             self.figure.draw(self.renderer)
    431         finally:
    432             if toolbar:

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
   1293 
   1294             mimage._draw_list_compositing_images(
-> 1295                 renderer, self, artists, self.suppressComposite)
   1296 
   1297             renderer.close_group('figure')

/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
   2397             renderer.stop_rasterizing()
   2398 
-> 2399         mimage._draw_list_compositing_images(renderer, self, artists)
   2400 
   2401         renderer.close_group('axes')

/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
   1133         ticks_to_draw = self._update_ticks(renderer)
   1134         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1135                                                                 renderer)
   1136 
   1137         for tick in ticks_to_draw:

/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
   1073         for tick in ticks:
   1074             if tick.label1On and tick.label1.get_visible():
-> 1075                 extent = tick.label1.get_window_extent(renderer)
   1076                 ticklabelBoxes.append(extent)
   1077             if tick.label2On and tick.label2.get_visible():

/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
    968             raise RuntimeError('Cannot get window extent w/o renderer')
    969 
--> 970         bbox, info, descent = self._get_layout(self._renderer)
    971         x, y = self.get_unitless_position()
    972         x, y = self.get_transform().transform_point((x, y))

/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
    352         tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
    353                                                          self._fontproperties,
--> 354                                                          ismath=False)
    355         offsety = (lp_h - lp_bl) * self._linespacing
    356 

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_text_width_height_descent(self, s, prop, ismath)
    233 
    234         flags = get_hinting_flag()
--> 235         font = self._get_agg_font(prop)
    236         font.set_text(s, 0.0, flags=flags)  # the width and height of unrotated string
    237         w, h = font.get_width_height()

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in _get_agg_font(self, prop)
    270         font = get_font(
    271             fname,
--> 272             hinting_factor=rcParams['text.hinting_factor'])
    273 
    274         font.clear()

/anaconda2/lib/python2.7/site-packages/backports/functools_lru_cache.pyc in wrapper(*args, **kwds)
    135                         stats[HITS] += 1
    136                         return result
--> 137                 result = user_function(*args, **kwds)
    138                 with lock:
    139                     root, = nonlocal_root

RuntimeError: In FT2Font: Can not load face.

<matplotlib.figure.Figure at 0x1114e6290>

I have tried uninstall it. and another code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
obj = pd.Series([4, 7, -5, 3])
print type(obj)
obj
plt.plot(obj)
plt.show()

And still show errors:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/anaconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    332                 pass
    333             else:
--> 334                 return printer(obj)
    335             # Finally look for special method names
    336             method = get_real_method(obj, self.print_method)

/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
    238 
    239     if 'png' in formats:
--> 240         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    241     if 'retina' in formats or 'png2x' in formats:
    242         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    122 
    123     bytes_io = BytesIO()
--> 124     fig.canvas.print_figure(bytes_io, **kw)
    125     data = bytes_io.getvalue()
    126     if fmt == 'svg':

/anaconda2/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2206                     orientation=orientation,
   2207                     dryrun=True,
-> 2208                     **kwargs)
   2209                 renderer = self.figure._cachedRenderer
   2210                 bbox_inches = self.figure.get_tightbbox(renderer)

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    505 
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--> 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
    428             if toolbar:
    429                 toolbar.set_cursor(cursors.WAIT)
--> 430             self.figure.draw(self.renderer)
    431         finally:
    432             if toolbar:

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
   1293 
   1294             mimage._draw_list_compositing_images(
-> 1295                 renderer, self, artists, self.suppressComposite)
   1296 
   1297             renderer.close_group('figure')

/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
   2397             renderer.stop_rasterizing()
   2398 
-> 2399         mimage._draw_list_compositing_images(renderer, self, artists)
   2400 
   2401         renderer.close_group('axes')

/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
   1133         ticks_to_draw = self._update_ticks(renderer)
   1134         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1135                                                                 renderer)
   1136 
   1137         for tick in ticks_to_draw:

/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
   1073         for tick in ticks:
   1074             if tick.label1On and tick.label1.get_visible():
-> 1075                 extent = tick.label1.get_window_extent(renderer)
   1076                 ticklabelBoxes.append(extent)
   1077             if tick.label2On and tick.label2.get_visible():

/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
    968             raise RuntimeError('Cannot get window extent w/o renderer')
    969 
--> 970         bbox, info, descent = self._get_layout(self._renderer)
    971         x, y = self.get_unitless_position()
    972         x, y = self.get_transform().transform_point((x, y))

/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
    352         tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
    353                                                          self._fontproperties,
--> 354                                                          ismath=False)
    355         offsety = (lp_h - lp_bl) * self._linespacing
    356 

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_text_width_height_descent(self, s, prop, ismath)
    233 
    234         flags = get_hinting_flag()
--> 235         font = self._get_agg_font(prop)
    236         font.set_text(s, 0.0, flags=flags)  # the width and height of unrotated string
    237         w, h = font.get_width_height()

/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in _get_agg_font(self, prop)
    270         font = get_font(
    271             fname,
--> 272             hinting_factor=rcParams['text.hinting_factor'])
    273 
    274         font.clear()

/anaconda2/lib/python2.7/site-packages/backports/functools_lru_cache.pyc in wrapper(*args, **kwds)
    135                         stats[HITS] += 1
    136                         return result
--> 137                 result = user_function(*args, **kwds)
    138                 with lock:
    139                     root, = nonlocal_root

RuntimeError: In FT2Font: Can not load face.

<matplotlib.figure.Figure at 0x113232250>
like image 709
Geraldine Chan Avatar asked Feb 04 '18 00:02

Geraldine Chan


1 Answers

I was facing same issue while using anaconda and spyder with python 3+ on MacOS. I am not sure if this solution would work for you but i solved it by deleting all files and folder in:

/Users/YOUR_USER/.matplotlib

and then uninstalling and reinstalling 'matplotlib' from my environment in Anaconda Navigator.

like image 162
Omer Shafiq Avatar answered Sep 22 '22 13:09

Omer Shafiq