def plot(self, fig):
ax = fig.gca()
当删除Qt
MatPlotLib
小部件上的项时,将调用此plot函数。最后,.draw()
将更新所有内容。出现的问题如下:
调用完成绘图的外部函数,ax
必须是当前轴(fig/axis不作为参数传递)。因此我不得不补充
一切都很好。不知何故,可能是因为更新到python(x,y)2.7.5.1(mpl是1.3.1),我得到了这个错误Axes instance argument was not found in a figure.
只是在这种情况下,当我想要这个外部函数(scipy dendrogram func)在预定义的轴上绘制。我试着跟着它
[Dbg]>>> fig
<matplotlib.figure.Figure object at 0x0A119A90>
[Dbg]>>> fig.gca()
<matplotlib.axes.AxesSubplot object at 0x0A119CD0>
然后进入子例程pyplot.sca(ax)
managers = _pylab_helpers.Gcf.get_all_fig_managers()
for m in managers:
if ax in m.canvas.figure.axes:
_pylab_helpers.Gcf.set_active(m)
m.canvas.figure.sca(ax)
return
raise ValueError("Axes instance argument was not found in a figure.")
名单似乎是空的
[Dbg]>>> managers
[]
也许你们有些人有个想法,可能是什么问题,尽管远程诊断可能很困难。在我想要的图/轴上绘制dendrogram
图的另一种方法也很有用。在
还请给出一个提示,说明应该使用什么来更新绘图,因为MatplotlibWidget
,figure
和{draw
方法。在
编辑:试图创建MWE。难道没有人遇到同样的错误吗?或者谁能告诉我这里出了什么问题?在
import sys
from matplotlibwidget import MatplotlibWidget
from matplotlib import pyplot
from PyQt4.QtGui import QMainWindow, QApplication
import scipy.cluster.hierarchy as hac
import numpy as np
class ApplicationWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.mplwidget = MatplotlibWidget(self, title='Example',
xlabel='Observation', ylabel='Distance', hold=True)
self.mplwidget.setFocus()
self.setCentralWidget(self.mplwidget)
def plotScree(self, Z, fig):
ax = fig.gca()
ax.plot(range(len(Z)), Z[::-1,2])
def plot(self, Z, fig):
ax = fig.gca()
pyplot.sca(ax)
hac.dendrogram(Z)
app = QApplication(sys.argv)
win = ApplicationWindow()
X = np.random.random(100).reshape(25, 4)
Z = hac.linkage(X)
#win.plotScree(Z, win.mplwidget.figure)
win.plot(Z, win.mplwidget.figure)
win.show()
sys.exit(app.exec_())
Python(x,y)中
matplotlibwidget
的实现似乎被破坏了。在我相信有问题的文件是this1。如果您将该文件的第67行改为
self.figure = pypolt.figure(figsize=(width, height), dpi=dpi)
,那么您的代码将按您的需要工作。我已经包含了下面修改过的代码的完整副本,这样您就可以将其复制/粘贴到您的项目中,并使用matplotlibwidget,而不是从python(x,y)导入问题似乎是直接实例化Figure对象会跳过整个Figure管理器构造的负载,这就是引发该错误的原因。我建议你用Python(x,y)提交一个bug报告并链接到这篇文章!在
带修改行的完整代码(请参阅上面的存储库链接以获取许可证)
相关问题 更多 >
编程相关推荐