SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Thomas R. <tho...@gm...> - 2009年03月31日 19:56:43
Hello,
I am using matplotlib to create postscript and SVG files. I am 
currently using imshow to show the contents of an array, but this 
means that when saving vector graphics files, matplotlib resamples the 
image/array onto a finer grid. What I would like, is for code such as 
this:
import matplotlib
matplotlib.use('PS')
from matplotlib.pyplot import *
import numpy as np
image = np.random.random((10,10))
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.imshow(image)
fig.savefig('example1.ps')
fig = figure(figsize=(8,8))
ax = fig.add_subplot(111)
ax.imshow(image)
fig.savefig('example2.ps')
to produce files that are the roughly the same size, rather than 
different by a factor of 4. In addition, both files should be very 
small since they should only contain a 10x10 bitmap in addition to the 
axes+labels. Postscript and SVG (as languages) both allow a bitmap of 
an arbitrary resolution to be scaled, translated, and rotated without 
resampling.
I have come across the figimage method which is meant to place an 
array in a plot without resampling, but I cannot figure out how to use 
it like imshow, i.e. to show the image inside the axes as before. I've 
also tried the pcolor functions, but it seems like they define each 
pixel as an individual polygon, which is inefficient.
I was wondering if anyone had a solution to this, or if there are 
plans to make matplotlib behave like this in future?
Thanks,
Thomas
From: John H. <jd...@gm...> - 2009年03月31日 20:32:38
On Tue, Mar 31, 2009 at 2:56 PM, Thomas Robitaille
<tho...@gm...> wrote:
> Hello,
>
> I am using matplotlib to create postscript and SVG files. I am
> currently using imshow to show the contents of an array, but this
> means that when saving vector graphics files, matplotlib resamples the
> image/array onto a finer grid. What I would like, is for code such as
> this:
I believe pcolor will be closer to what you are looking for.7
JDH
From: Thomas R. <tho...@gm...> - 2009年03月31日 20:52:46
The problem with pcolor is that it draws all the pixels as polygons, 
which is very inefficient in terms of file size. For example,
import matplotlib
matplotlib.use('PS')
from matplotlib.pyplot import *
import numpy as np
image = np.random.random((100,100))
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolor(image)
fig.savefig('plot.ps')
produces a 2Mb+ file.
Thanks,
Thomas
On Mar 31, 2009, at 4:32 PM, John Hunter wrote:
> On Tue, Mar 31, 2009 at 2:56 PM, Thomas Robitaille
> <tho...@gm...> wrote:
>> Hello,
>>
>> I am using matplotlib to create postscript and SVG files. I am
>> currently using imshow to show the contents of an array, but this
>> means that when saving vector graphics files, matplotlib resamples 
>> the
>> image/array onto a finer grid. What I would like, is for code such as
>> this:
>
>
> I believe pcolor will be closer to what you are looking for.7
>
> JDH
From: Thomas R. <tho...@gm...> - 2009年04月02日 15:32:36
I've looked into this some more, and while pcolor draws pixels 
inefficiently as polygons, pcolorfast does appear to be writing the 
data as a bitmap into the eps file, so this is closer to what I need.
However, while this works great with the SVG driver, it seems that 
pcolorfast still produces quite large files with the PS driver. For 
example,
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import *
import numpy as np
image = np.random.random((100,100))
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('plot.eps')
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('plot.svg')
produces a 600k ps file and a 60k svg file. In fact, the PS file size 
remains the same if I change the size of the array.
So pcolorfast does appear to be the solution, but the output is not 
properly handled for PS files. Is this something that could be fixed 
in future?
Thanks,
Thomas
On Mar 31, 2009, at 4:32 PM, John Hunter wrote:
> On Tue, Mar 31, 2009 at 2:56 PM, Thomas Robitaille
> <tho...@gm...> wrote:
>> Hello,
>>
>> I am using matplotlib to create postscript and SVG files. I am
>> currently using imshow to show the contents of an array, but this
>> means that when saving vector graphics files, matplotlib resamples 
>> the
>> image/array onto a finer grid. What I would like, is for code such as
>> this:
>
>
> I believe pcolor will be closer to what you are looking for.7
>
> JDH
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /