我正在用PyQt编写一个应用程序,用matplotlib显示一些图形。为此,我使用以下代码:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
import matplotlib.figure as fig
self.IntFig = fig.Figure()
self.IntBeamCanvas = FigureCanvasQTAgg(self.IntFig)
self.AxesIntInit = self.IntFig.add_subplot(111)
self.AxesIntInit.hold(False)
self.AxesIntInit.imshow(self.Int,extent =[-xx/2+xx/N,xx/2,-xx/2+xx/N,xx/2])
self.IntBeamCanvas.draw()
在后面的代码中,我设法保存了用以下代码创建的图形:
fname = QtGui.QFileDialog.getSaveFileName(self,'Save Intensity','C:' )
self.IntFig.savefig(str(fname))
但这只会节省数字(我指的是斧头)。如果我只想保存数据呢
self.Int
显示出来的?我知道pyplot.imsave方法,但不知道如何在这里使用它,因为我不是使用pyplot,而是使用figure.Figure。
有人有主意吗?
发布于 2014-02-05 12:35:05
您可以通过以下方法保存图像:
import numpy as np
import pylab as pl
y, x = np.ogrid[-1:1:50j, -1:1:100j]
z = np.sqrt(x*x + y*y)
im = pl.imshow(z)
img = im.make_image()
h, w, s = img.as_rgba_str()
a = np.fromstring(s, dtype=np.uint8).reshape(h, w, 4)
pl.imsave("tmp.png", a)
保存的图像:
https://stackoverflow.com/questions/21573941
复制相似问题