【发布时间】:2016-11-08 00:24:42
【问题描述】:
“根据这个SO note,嵌入时不应该导入pyplot。它会做一些时髦的事情,比如用自己的主循环运行自己的GUI。”
如果是这样,如何在不调用 plt.axes() 的情况下传递 Slider 所需的 matplotlib.axes._axes.Axes 参数? 在 GUI based on matplotlib documentation 中,我们[添加了以下内容以包含滑块]:
def compute_initial_figure(self):
ymax = 300
window_size=1
res= 0.1
ax= self.axes
t = np.arange(0.0, 100.0, 0.1)
s = np.sin(2*np.pi*t)
ax.plot(t, s)
ax.axis([0, window_size, -ymax, ymax])
ax.get_xaxis().get_major_formatter().set_useOffset(False)
axcolor = 'lightgoldenrodyellow'
axpos = plt.axes([.1, .1, 0.75, 0.05], axisbg=axcolor) #MAKES OWN FIG!
spos = Slider(axpos, 'Time', res, t[-1], valinit=0)
spos.on_changed(update)
axpos 行使用 plt 并创建自己的图形,与 Qt 窗口分开。注意 plt.axes 返回一个 matplotlib.axes._axes.Axes 对象而不是 matplotlib.axes._subplots.AxesSubplot 对象。
类似问题:
When matplotlib is embedded in PyQt4 how are axes/subplots labelled without using pyplot?
Combining PyQt and Matplotlib
【问题讨论】:
-
页面matplotlib.org/examples/user_interfaces/embedding_in_qt4.html似乎没有那种
compute_initial_figure()。 -
正确,这是一个修改后的 compute_initial_figure():包含一个滑块。
标签: python-2.7 matplotlib pyqt4