gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:43:52 24 4
gpt4 key购买 nike

  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()

那么如何使用命令保存这张图片呢?

最佳答案

我没有 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')

关于python - 保存在 python 中使用 peek() 显示的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32919522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com