【发布时间】:2011-02-17 13:40:39
【问题描述】:
我的问题是:
我在 PyGTK 应用程序中有 Matplotlib 图形,每隔几秒钟就会不断更新。我添加了将图形作为 PNG 文件保存到磁盘的功能。调用figure.savefig(filename, other parameters) 后,我在应用程序中的图形停止更新。
图初始化阶段:
# setup matplotlib stuff on empty space in vbox4
figure = Figure()
canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea
canvas.show()
self.win.get_widget('vbox4').pack_start(canvas, True, True) # this will be aded to last place
self.win.get_widget('vbox4').reorder_child(canvas, 1) #place plot to space where it should be
图形正在以这种方式更新(这在单独的线程中每隔几秒调用一次):
def _updateGraph(self, fig, x, x1, y):
#Various calculations done here
fig.clf()#repaint plot: delete current and formate a new one
axis = fig.add_subplot(111)
#axis.set_axis_off()
axis.grid(True)
#remove ticks and labels
axis.get_xaxis().set_ticks_position("none")
for i in range(len(axis.get_xticklabels())): axis.get_xticklabels()[i].set_visible(False)
axis.get_yaxis().set_ticks_position("none")
axis.plot(numpy.array(x),numpy.array(y)/(1.0**1), "k-" ,alpha=.2)
axis.set_title('myTitle')
fig.autofmt_xdate()
fig.canvas.draw()
一切都按预期进行。但调用后:
figure.savefig(fileName, bbox_inches='tight', pad_inches=0.05)
文件已保存,但我的屏幕上的人物停止更新。
任何想法如何将图保存到磁盘并仍然能够在屏幕上更新我的图?
【问题讨论】:
-
一个独立的例子可能会有所帮助。也就是说,没有人知道“gui”是什么,如何从这些代码片段中调用 savefig 等等。当然,您会希望将其缩减为不是太多行但会显示问题的内容。
-
感谢您帮助我。是的,我知道这段代码没用,不能独立运行。图保存方法由按钮按下事件调用。
gui.w().get("figureMain")是我个人的全球使用对象。它只是一个变量。我将尝试创建示例应用程序
标签: python save pygtk matplotlib