0

我在运行 python 和 matplotlib 时遇到问题

from matplotlib import rc
import matplotlib.cm as cm
from matplotlib.ticker import MultipleLocator


scoreArray = [3,8,7,8,9,0]
scoreArrayIsopmap = [3,4,7,1,3,0]
scoreArrayPCA = [0,1,7,6,3,15]

rc('font',**{'family':'Bitstream Vera Sans','serif': ['Palatino']})
rc('text', usetex=True)

fig, (ax1) = plt.subplots(1,1, figsize=(7,5))

ax1.plot(range(0,6), scoreArray, color = 'b', ls='-', lw=4, alpha=0.7, label="A Priori Manifold")
ax1.plot(range(0,6), scoreArrayIsopmap, color = 'r', ls='-', lw=4, alpha=0.7, label="Isomap")
ax1.plot(range(0,6), scoreArrayPCA, color = 'g', ls='-', lw=4, alpha=0.7, label="PCA")

ax1.xaxis.set_major_locator(MultipleLocator(10))
ax1.grid(which='major', axis='x', linewidth=0.25, linestyle='-', color='0.75') 
ax1.grid(True) 
ax1.set_ylabel('Dunn Index') 
ax1.set_xlabel('Number Of Components')

在此处输入图像描述

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

1419             self.set_frameon(frameon)
1420 
-> 1421         self.canvas.print_figure(*args, **kwargs)
1422 
1423         if frameon:

/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self,    filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2218                 orientation=orientation,
2219                 bbox_inches_restore=_bbox_inches_restore,
-> 2220                 **kwargs)
2221         finally:
2222             if bbox_inches and restore_bbox:

/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_pdf(self, *args, **kwargs)
1950         from backends.backend_pdf import FigureCanvasPdf  # lazy import
1951         pdf = self.switch_backends(FigureCanvasPdf)
-> 1952         return pdf.print_pdf(*args, **kwargs)
1953 
1954     def print_pgf(self, *args, **kwargs):

/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.pyc in print_pdf(self, filename, **kwargs)
2338                                          width, height, image_dpi, RendererPdf(file, image_dpi),
2339                                          bbox_inches_restore=_bbox_inches_restore)
-> 2340             self.figure.draw(renderer)
2341             renderer.finalize()
2342         finally:

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52     def draw_wrapper(artist, renderer, *args, **kwargs):
53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
55         after(artist, renderer)
56 

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
1032         dsu.sort(key=itemgetter(0))
1033         for zorder, a, func, args in dsu:
-> 1034             func(*args)
1035 
1036         renderer.close_group('figure')

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52     def draw_wrapper(artist, renderer, *args, **kwargs):
53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
55         after(artist, renderer)
56 

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe)
2084 
2085         for zorder, a in dsu:
-> 2086             a.draw(renderer)
2087 
2088         renderer.close_group('axes')

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52     def draw_wrapper(artist, renderer, *args, **kwargs):
53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
55         after(artist, renderer)
56 

/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1087         ticks_to_draw = self._update_ticks(renderer)
1088         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1089                                                                 renderer)
1090 
1091         for tick in ticks_to_draw:

/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
1036         for tick in ticks:
1037             if tick.label1On and tick.label1.get_visible():
-> 1038                 extent = tick.label1.get_window_extent(renderer)
1039                 ticklabelBoxes.append(extent)
1040             if tick.label2On and tick.label2.get_visible():

/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
751             raise RuntimeError('Cannot get window extent w/o renderer')
752 
--> 753         bbox, info, descent = self._get_layout(self._renderer)
754         x, y = self.get_position()
755         x, y = self.get_transform().transform_point((x, y))

/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
318         tmp, lp_h, lp_bl = get_text_width_height_descent('lp',
319                                                          self._fontproperties,
--> 320                                                          ismath=False)
321         offsety = (lp_h - lp_bl) * self._linespacing
322 

/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.pyc in    get_text_width_height_descent(self, s, prop, ismath)
1945     def get_text_width_height_descent(self, s, prop, ismath):
1946         if rcParams['text.usetex']:
-> 1947             texmanager = self.get_texmanager()
1948             fontsize = prop.get_size_in_points()
1949             w, h, d = texmanager.get_text_width_height_descent(s, fontsize,

/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in get_texmanager(self)
612         if self._texmanager is None:
613             from matplotlib.texmanager import TexManager
--> 614             self._texmanager = TexManager()
615         return self._texmanager
616 

/usr/local/lib/python2.7/site-packages/matplotlib/texmanager.pyc in __init__(self)
170         if len(ff) == 1 and ff[0].lower() in self.font_families:
171             self.font_family = ff[0].lower()
--> 172         elif ff.lower() in self.font_families:
173             self.font_family = ff.lower()
174         else:

AttributeError: 'list' object has no attribute 'lower'

我得到了上面的图像,但轴不可见。我运行 python 2.7.5 和 matplotlib 1.3。我在 Mac 上工作,它在不同的 Mac 上工作正常。直到 2 天前,它对我的​​工作正常。

有人知道为什么会这样吗?

4

1 回答 1

2

这里有两件事:

  1. 从 matplotlib 代码:

    当 text.usetex 为 True 时,font.family 必须是 (serif, sans-serif, cursive, monospace) 之一。默认情况下将使用衬线。

    因此,如果您使用 ,text.usetex则应将 设置font.family为受支持的值之一。

  2. 您在 matplotlib 1.3.0 中发现了一个错误 :) 但它已经在开发分支上修复了。因此,在下一个版本中,您将不会收到该错误。

于 2013-09-19T10:05:33.170 回答