【发布时间】:2013-05-01 11:41:59
【问题描述】:
我有一个小的 python 程序,它接收数据并使用 matplotlib (v1.3.x) 绘制它。情节有一个可拖动的传说。它在 Windows 上渲染良好,但在 Mac (OS 10.8.3) 上出现错误。代码首先创建一个图形,然后使用该图形创建一个子图,该子图返回一个轴。我正在使用轴对象来创建图例。类似这样:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
lines = ax.plot([1,2,3,4])
legend = ax.legend(lines, loc=2)
legend.draggable()
plt.show()
这是我得到的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/legend.py", line 1007, in draggable
update=update)
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/legend.py", line 54, in __init__
use_blit=use_blit)
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/offsetbox.py", line 1540, in __init__
DraggableBase.__init__(self, ref_artist, use_blit=use_blit)
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/offsetbox.py", line 1462, in __init__
self.canvas = self.ref_artist.figure.canvas
AttributeError: 'DraggableLegend' object has no attribute 'ref_artist'
我在网上没有找到任何可以解释这个错误或为什么可拖动图例在 mac 上不起作用的东西。我确实在 matplotlib 文档中找到了这个:Note that not all kinds of artist are supported by the legend yet,但我不知道这是否适用于此。
有人可以帮忙吗?
【问题讨论】:
-
你的代码可以在我的linux机器上使用
1.2.1版本的matplotlib,这是最新的stable版本
标签: python macos matplotlib legend