English 中文(简体)
用jpeg格式节省的费用
原标题:matplotlib savefig in jpeg format

我正在使用校正(皮拉布)显示数字。 我想以jpg格式挽救他们。 当我简单地利用救护指挥部,把这一权力延伸到:

ValueError: Format "jpg" is not supported.

Supported Format: emf, eps, pdf, png, ps, original, rgba, svg, svgz.

是否有办法做到这一点?

问题回答

你们可以挽救一个形象,并使用假日成像图书馆(PIL)将这一档案转换为 j:

import Image
import matplotlib.pyplot as plt

plt.plot(range(10))
plt.savefig( testplot.png )
Image.open( testplot.png ).save( testplot.jpg , JPEG )

原件:

“enterography

JPEG形象:

“entergraph

澄清和更新@neo 有用答案和原始问题。 清洁的解决办法包括安装Pillow,这是一个更新版的Sharma图像图书馆。 采用这种方法

pip install pillow

Once Pillow is installed, the standard Matplotlib commands

import matplotlib.pyplot as plt

plt.plot([1, 2])
plt.savefig( image.jpg )

will save the figure into a JPEG file and will not generate a ValueError any more.

与“@amillerrhodes”的答复相反,截至Matplotlib 3.1,JPEG的档案仍然没有得到支持。 如果我去除Pillar包裹,我仍然收到一个未证实的档案类型。

Just install pillow with pip install pillow and it will work.

我刚刚更新了该系统的校正-1.1.0,现在允许我用<代码>savefig save。

升级为1.1.0和pip,使用这一指令:

pip install -U  http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz/download 

<EDIT (针对评论):

pylab is simply an aggregation of the matplotlib.pyplot and numpy namespaces (as well as a few others) jinto a single namespace.

在我的系统中,<代码>pylab只是:

from matplotlib.pylab import *
import matplotlib.pylab
__doc__ = matplotlib.pylab.__doc__

您可以看到,pylab<>/code>只是您的校正安装的另一个名称空间。 因此,无论你是否以<代码>pylab进口,或以<代码>matplotlib.pyplot进口,都无关紧要。

如果你仍然遇到问题,那么我会猜测一下aco子的背后,不会支持储蓄地平息。 你可以尝试使用不同的支持者。 See here

如果你安装了消费物价指数,可直接、透明地处理垃圾。 你们不需要说话,而是自己这样做。 如果不找到临时自治机构,那就会产生错误。





相关问题
Create a Video Stream (AVI) from a Series of Images

There is an IP web camera that I wrote a .NET class for sometime ago. It s basically a Timer implementation that pings a snapshot CGI script from the camera every five seconds. The camera itself is ...

JPG+Zip File Combination Problem with Zip Format

Hopefully you ve heard of the neat hack that lets you combine a JPG and a Zip file into a single file and it s a valid (or at least readable) file for both formats. Well, I realized that since JPG ...

c# converting HTML to JPG

I am trying to download image from HTTP URL to my computer via c#. Example picture: http://www.hcs.harvard.edu/csharp/Logo1.png I am using cURL to fletch it. Then I am saving it to computer as ...

Scale a .jpg file in WPF

I d like to open a .jpg file in WPF, scale it down to around 50%, then save it back to the file system. What s a good/efficient way to go about doing that?

How to Add Comments to a JPEG File Using C#

Within the property window of a JPEG image, there is a tab called Summary . Within this tab, there is a field called Comments I would like to write some c# code which will add a given string to ...

热门标签