我正在尝试学习使用matplotlib并遵循教程绘制散点图,我指定了点的大小。 (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter)
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses
plt.scatter(x, y, s=area, alpha=0.5)
plt.show()
我使用命令ipython --pylab
在Mac OS X上运行ipython并收到以下错误。
AttributeError Traceback (most recent call last)
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/figure.pyc in draw(self, renderer)
1048 dsu.sort(key=itemgetter(0))
1049 for zorder, a, func, args in dsu:
-> 1050 func(*args)
1051
1052 renderer.close_group('figure')
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2074
2075 for zorder, a in dsu:
-> 2076 a.draw(renderer)
2077
2078 renderer.close_group('axes')
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/collections.pyc in draw(self, renderer)
733 def draw(self, renderer):
734 self.set_sizes(self._sizes, self.figure.dpi)
--> 735 Collection.draw(self, renderer)
736
737
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/collections.pyc in draw(self, renderer)
305 self._linewidths, self._linestyles,
306 self._antialiaseds, self._urls,
--> 307 self._offset_position)
308
309 gc.restore()
/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/backends/backend_macosx.pyc in draw_path_collection(self, gc, master_transform, paths, all_transforms, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds, urls, offset_position)
77 path_ids.append((path, transform))
78 master_transform = master_transform.get_matrix()
---> 79 all_transforms = [t.get_matrix() for t in all_transforms]
80 offsetTrans = offsetTrans.get_matrix()
81 gc.draw_path_collection(master_transform, path_ids, all_transforms,
AttributeError: 'numpy.ndarray' object has no attribute 'get_matrix'
但是,如果我在使用命令ipython notebook --pylab=inline
开始的ipython笔记本中运行相同的代码,它可以正常工作。
如何从控制台进行此操作?
其他信息:
ipython
代替ipython --pylab
,我会得到相同的结果
错误。由于
答案 0 :(得分:2)
backend
方看起来是matplotlib
问题。查看错误消息的最后一部分。它表示macosx
backend
中的某些内容不正确,OSX
pylab=inline
用作inline
环境中的交互式后端。
它在内联模式下工作的原因:matplotlib
证实了这一点。与内联模式一样,它不是交互式后端,而是一个正在进行工作的非交互式后端(最有可能是{{1}}后端)。所以,它的工作原理。
解决方案可能是@Matt建议的,切换到{{1}}
的稳定版本