如何在PyQ中将数组另存为映像

2024-10-06 07:04:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用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()

在后面的代码中,我设法保存使用以下代码创建的地物:

^{pr2}$

但这只保存了数字(我的意思是用它的轴)。如果我只想保存数据呢

self.Int

显示了什么?我知道pyplot.imsave方法,但不知道如何在这里使用它,因为我不使用pyplot但是图。图. 在

有人有主意吗?在


Tags: 代码importself应用程序图形matplotlibfigpyqt
1条回答
网友
1楼 · 发布于 2024-10-06 07:04:15

您可以通过以下方法保存图像:

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)

保存的图像:

enter image description here

相关问题 更多 >