jpeg格式的matplotlib savefig [英] matplotlib savefig in jpeg format
本文介绍了jpeg格式的matplotlib savefig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用matplotlib(在pylab中)显示数字.我想将它们保存为.jpg格式.当我只使用带有jpg扩展名的savefig命令时,将返回:
I am using matplotlib (within pylab) to display figures. And I want to save them in .jpg format. When I simply use the savefig command with jpg extension this returns :
ValueError: Format "jpg" is not supported.
Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz.
是否可以执行此操作?
推荐答案
您可以将图像另存为"png",并使用python图像库(PIL)将此文件转换为"jpg":
You can save an image as 'png' and use the python imaging library (PIL) to convert this file to 'jpg':
import Image
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.savefig('testplot.png')
Image.open('testplot.png').save('testplot.jpg','JPEG')
原件:
JPEG图像:
这篇关于jpeg格式的matplotlib savefig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文