[英]use a matplotlib Figure in PyQt
在这里编程菜鸟。 我正在尝试在PyQt4 GUI中使用matplotlib小部件。 该小部件类似于matplotlib的qt示例 。
在某些时候,用户需要单击该图,我认为类似ginput()的东西可以处理。 但是,这不起作用,因为该人物没有经理(请参见下文)。 请注意,这与另一个问题非常相似,但从未得到解答。
AttributeError: 'NoneType' object has no attribute 'manager'
Figure.show works only for figures managed by pyplot, normally created by pyplot.figure().
我假设通过“正常”可以解决此问题。
另一个简单的脚本演示:
from __future__ import print_function
from matplotlib.figure import Figure
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 5, 0.1)
y = np.sin(x)
# figure creation by plt (also given a manager, although not explicitly)
plt.figure()
plt.plot(x,y)
coords = plt.ginput() # click on the axes somewhere; this works
print(coords)
# figure creation w/o plt
manualfig = Figure()
manualaxes = manualfig.add_subplot(111)
manualaxes.plot(x,y)
manualfig.show() # will fail because of no manager, yet shown as a method
manualcoords = manualfig.ginput() # comment out above and this fails too
print(manualcoords)
像pyplot一样流行(没有它我几乎找不到答案),在使用GUI时,它似乎不能很好地发挥作用。 我认为pyplot只是OO框架的包装,但我想我只是菜鸟。
然后我的问题是:是否可以将pyplot附加到matplotlib.figure.Figure的实例? 有没有简单的方法可以将经理附加到人物上? 我在matplotlib.backends.backend_qt4agg中找到了new_figure_manager(),但即使它是正确的解决方案,也无法使它正常工作。
非常感谢,
詹姆士
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.