[英]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.