我正在尝试绘制一个酒吧。但它显示运行时错误,并显示在FT2Font:无法加载面。在波顿。 我已经尝试卸载并再次安装它。并尝试了另一种方法,但仍然无法正常工作。我认为代码是正确的,因为我在Windows笔记本电脑上成功运行它。我的jupyter笔记本适用于Mac python 2.7。
代码如下:
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])
但它显示了一些错误:
<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>
我试过卸载它。和另一个代码:
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()
仍然显示错误:
---------------------------------------------------------------------------
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>
答案 0 :(得分:0)
我在MacOS上使用带有python 3+的anaconda和spyder时遇到了同样的问题。 我不确定这个解决方案是否适合您,但我通过删除所有文件和文件夹来解决它:
/Users/YOUR_USER/.matplotlib
然后从 Anaconda Navigator 中的环境中卸载并重新安装&#39; matplotlib&#39; 。
答案 1 :(得分:0)
我只是遇到了这个错误-查看matplotlib调试日志,一切似乎都正常。但是,当我检查所选字体的路径时,文件大小为0KB。安装matplotlib时,它可能已损坏。
将字体文件从另一台计算机复制到字体目录中可以解决此问题。
好,路径为%CONDA_ENV%\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
(我在Windows上使用的是conda,但相对于本地安装中的site-packages目录,路径应相同)。重新安装matplotlib将解决此问题,但值得检查此文件夹,以防万一该问题只是一个不良的字体文件。