我正在使用校正(皮拉布)显示数字。 我想以jpg格式挽救他们。 当我简单地利用救护指挥部,把这一权力延伸到:
ValueError: Format "jpg" is not supported.
Supported Format: emf, eps, pdf, png, ps, original, rgba, svg, svgz.
是否有办法做到这一点?
我正在使用校正(皮拉布)显示数字。 我想以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 )
原件:
JPEG形象:
澄清和更新@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。
如果你安装了消费物价指数,可直接、透明地处理垃圾。 你们不需要说话,而是自己这样做。 如果不找到临时自治机构,那就会产生错误。
我不肯定所有版本的马塔普图利,但官方网站documentation ,用于v3.5.0 savfig,使你能够把环境经过深层的皮洛图书馆,而任何途径都能够挽救图像。 因此,如果你想要一个带有特定压缩环境的支部,例如:
import matplotlib.pyplot as plt
plt.plot(...) # Plot stuff
plt.savefig( filename.jpg , pil_kwargs={
quality : 20,
subsampling : 10
})
这应当给你一个产出高度压缩的jpg。
Just for completeness, if you also want to control the quality (i.e. compression level) of the saved result, it seems to get a bit more complicated, as directly passing plt.savefig(..., quality=5)
does not seem to have an effect on the output size and quality. So, on the one hand, one could either go the way of saving the result as a png first, then reloading it with PIL
, then saving it again as a jpeg, using PIL
s quality
parameter – similar to what is suggested in Yann s answer.
另一方面,可以通过使用<条码>避免这种装载和储蓄的偏离。 BytesIO(在https://stackoverflow.com/questions/30771652/>查询之后):
from io import BytesIO
import matplotlib.pyplot as plt
from PIL import Image
buf = BytesIO()
plt.plot(...) # Plot something here
plt.savefig(buf)
Image.open(buf).convert("RGB").save("testplot.jpg", quality=5)
I m attempting to convert a PDF to a JPEG using ImageMagick. The PDF: baby_aRCWTU.pdf The command: convert -density 260 -profile SWOP.icc -profile sRGB.icm baby_aRCWTU.pdf baby_aRCWTU.jpg The ...
I noticed when I saved my menu background image from jpg to gif that gif takes almost one fourth of the size that jpg does. jpg = 25kb gif = 7kb Is there any downsides to using gif? Its GIF 256 ...
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 ...
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 ...
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 ...
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?
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 ...
I v got a bitmap 24bits, I am writing application in c++, MFC, I am using libjpeg for encoding the bitmap into jpeg file 24bits. When this bitmap s width is M, and height is N. How to estimate jpeg ...