保存在python中使用peek()显示的图像

2024-04-20 10:47:56 发布

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

  import matplotlib.pyplot as plt
  import sunpy.spectra
  import sunpy.data.sample
  from sunpy.spectra.sources.callisto import CallistoSpectrogram
  image = CallistoSpectrogram.read(sunpy.data.sample.CALLISTO_IMAGE)
  image.peek()

那么如何用命令保存这个图像呢?你知道吗


Tags: samplefromimageimportreaddatamatplotlibas
1条回答
网友
1楼 · 发布于 2024-04-20 10:47:56

我没有一个SunPy环境来测试这个,但是你能给下面的一个镜头吗?你知道吗

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import sunpy.spectra
import sunpy.data.sample
from sunpy.spectra.sources.callisto import CallistoSpectrogram
image = CallistoSpectrogram.read(sunpy.data.sample.CALLISTO_IMAGE)
image.plot()
plt.savefig('myfig')

基于Generate images without having a window appear

The easiest way to do this is use a non-interactive backend (see What is a backend?) such as Agg (for PNGs), PDF, SVG or PS. In your figure-generating script, just call the matplotlib.use() directive before importing pylab or pyplot:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.savefig('myfig')

相关问题 更多 >