Re: [matplotlib-devel] [Fwd: [Matplotlib-users] imshow without resampling]

2009-04-05 Thread Thomas Robitaille

Hello,

I just thought I'd mention a little more detail about what I've found  
with respect to writing grey/colorscales to vector graphics formats.  
The bottom line is that to plot a grayscale or colorscale in a vector  
graphics format without resampling, it seems at the moment that  
pcolorfast works best, in SVG format (not PS).


Attached is a script to try out different combinations of methods,  
formats, and canvas sizes. In all cases I am plotting a 10x10 numpy  
array. The file sizes I obtain are:


$ du -sh example*
584Kexample1.ps(imshow and 4x4 canvas)
2.2Mexample2.ps(imshow and 8x8 canvas)
 84Kexample3.svg   (imshow and 4x4 canvas)
204Kexample4.svg   (imshow and 8x8 canvas)
600Kexample5.ps(pcolorfast and 4x4 canvas)
2.3Mexample6.ps(pcolorfast and 8x8 canvas)
 16Kexample7.svg   (pcolorfast and 4x4 canvas)
 20Kexample8.svg   (pcolorfast and 8x8 canvas)

As you can see, example7.svg and example8.svg are by far the smallest  
files, and their sizes aren't that different, which is the way things  
should be as changing the canvas size shouldn't be changing much since  
it is a vector graphics format. It's interesting to see that imshow  
and pcolorfast produce different results for SVG (both smaller than  
the PS results)


Interestingly, pcolorfast shows no improvement compared to imshow for  
the PS files, and in addition, the 4x4 images are 4 times smaller than  
the 8x8 images, suggesting that in all cases, the colorscale has been  
rasterized to a finer resolution.


It might be worth seeing how the SVG driver implements this and apply  
the same technique to the PS driver. The fact that the SVG driver can  
do this suggests that the matplotlib API should be able to handle this  
and so all that is needed is to work on the PS driver?


As a temporary solution, it is possible to produce SVG files and  
convert these to PS, but this is not an ideal solution.


Let me know if you have any questions about this,

Thanks,

Thomas


 import matplotlib
matplotlib.use('Agg')
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')

fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.imshow(image)
fig.savefig('example3.svg')

fig = figure(figsize=(8,8))
ax = fig.add_subplot(111)
ax.imshow(image)
fig.savefig('example4.svg')

fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('example5.ps')

fig = figure(figsize=(8,8))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('example6.ps')

fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('example7.svg')

fig = figure(figsize=(8,8))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('example8.svg')



On 4 Apr 2009, at 22:50, Eric Firing wrote:


Jouni, Darren,

I'm not sure who the SVG expert is, and I presume the attached  
message applies to pdf as well as ps.  I'm bringing it to your  
attention because it is suggesting what would seem to be significant  
improvements in some backends by taking better advantage of their  
native image support.  I know nothing about this; would either of  
you (or anyone else) like to comment?


Eric


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

--
___
Matplotlib-users mailing list
matp

[matplotlib-devel] PatchCollection does not preserve facecolor

2009-10-18 Thread Thomas Robitaille

Hi,
It seems that the PatchCollection class does not preserve the  
facecolor attribute of patches when match_original=True. I have  
submitted a bug report with a script to reproduce the issue:


https://sourceforge.net/tracker/?func=detail&aid=2881485&group_id=80706&atid=560720

Cheers,

Tom--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Problem with negative numbers in EPS files

2009-10-21 Thread Thomas Robitaille

Hi,

Running the simple attached test.py script creates a very simple  
test.eps. Converting this to a pdf file with ps2pdf causes the  
negative numbers to disappear (except the minus sign). Of course, the  
PDF backend can be used from the start, but there are situations (e.g.  
typesetting with LaTeX where one needs to include an EPS file, and the  
final document will be a PDF file, in which case the negative numbers  
disappear during the conversion). I have submitted a bug report:


https://sourceforge.net/tracker/?func=detail&aid=2883256&group_id=80706&atid=560720

Cheers,

Tom

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as mpl
fig = mpl.figure()
ax = fig.add_subplot(111)
ax.set_xlim(-100.,100.)
ax.set_ylim(-100.,100.)
fig.savefig('test.eps')




--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Bugs in pcolormesh

2010-07-26 Thread Thomas Robitaille
Hi,

I've come across two bugs with pcolormesh, one relating to the MacOSX backend, 
and the other relating to the linewidth argument being ignored. I've submitted 
tickets:

https://sourceforge.net/tracker/?func=detail&aid=3034775&group_id=80706&atid=560720
https://sourceforge.net/tracker/?func=detail&aid=3034778&group_id=80706&atid=560720

Cheers,

Tom
--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] ax.scatter broken for triangular markers

2010-08-18 Thread Thomas Robitaille
Hi,

I updated to the latest svn version of matplotlib this morning, and 
Axes.scatter seems to be broken when using marker='v', '>', '<', or '^':

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as mpl

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.scatter([1,2,3], [4,5,6], marker='v')
fig.savefig('test.png')

gives:

Traceback (most recent call last):
  File "test.py", line 7, in 
ax.scatter([1,2,3], [4,5,6], marker='^')
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/axes.py", line 
5764, in scatter
transOffset = self.transData,
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/collections.py", 
line 695, in __init__
self._paths = [self._path_generator(numsides)]
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/path.py", line 
415, in unit_regular_polygon
path = cls(verts, codes)
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/path.py", line 
117, in __init__
assert len(codes) == len(vertices)
AssertionError

This did not occur when I updated to the latest svn a couple of days ago, so it 
must be due to a pretty recent change.

Cheers,

Tom
--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] ax.scatter broken for triangular markers

2010-08-18 Thread Thomas Robitaille
I can confirm that this now works fine - thanks for the quick fix!

Tom

On Aug 18, 2010, at 12:09 PM, Michael Droettboom wrote:

> Should be fixed in r8648 now.
> 
> Mike
> 
> On 08/18/2010 11:45 AM, Thomas Robitaille wrote:
>> Hi,
>> 
>> I updated to the latest svn version of matplotlib this morning, and 
>> Axes.scatter seems to be broken when using marker='v', '>','<', or '^':
>> 
>> import matplotlib
>> matplotlib.use('Agg')
>> import matplotlib.pyplot as mpl
>> 
>> fig = mpl.figure()
>> ax = fig.add_subplot(1,1,1)
>> ax.scatter([1,2,3], [4,5,6], marker='v')
>> fig.savefig('test.png')
>> 
>> gives:
>> 
>> Traceback (most recent call last):
>>   File "test.py", line 7, in
>> ax.scatter([1,2,3], [4,5,6], marker='^')
>>   File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/axes.py", 
>> line 5764, in scatter
>> transOffset = self.transData,
>>   File 
>> "/Users/tom/Library/Python/2.6/site-packages/matplotlib/collections.py", 
>> line 695, in __init__
>> self._paths = [self._path_generator(numsides)]
>>   File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/path.py", 
>> line 415, in unit_regular_polygon
>> path = cls(verts, codes)
>>   File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/path.py", 
>> line 117, in __init__
>> assert len(codes) == len(vertices)
>> AssertionError
>> 
>> This did not occur when I updated to the latest svn a couple of days ago, so 
>> it must be due to a pretty recent change.
>> 
>> Cheers,
>> 
>> Tom
>> --
>> This SF.net email is sponsored by
>> 
>> Make an app they can't live without
>> Enter the BlackBerry Developer Challenge
>> http://p.sf.net/sfu/RIM-dev2dev
>> ___
>> Matplotlib-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>> 
> 
> 
> -- 
> Michael Droettboom
> Science Software Branch
> Space Telescope Science Institute
> Baltimore, Maryland, USA
> 
> 
> --
> This SF.net email is sponsored by 
> 
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev 
> ___
> Matplotlib-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Issue with Ellipses and PatchCollections

2010-08-27 Thread Thomas Robitaille
Hi,

The following code:

from matplotlib.patches import Ellipse
from matplotlib.collections import PatchCollection
p = PatchCollection([Ellipse((0.5,0.5),0.2,0.1)], match_original=True)

raises the following exception:

Traceback (most recent call last):
  File "test_patches.py", line 5, in 
p = PatchCollection([Ellipse((0.5,0.5),0.2,0.1)], match_original=True)
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/collections.py", 
line 1041, in __init__
facecolors   = [determine_facecolor(p) for p in patches]
  File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/collections.py", 
line 1037, in determine_facecolor
if patch.fill:
AttributeError: 'Ellipse' object has no attribute 'fill'

I have submitted a ticket: 
https://sourceforge.net/tracker/?group_id=80706&atid=560720

Cheers,

Tom
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Issue with linestyles and match_original in PatchCollection

2010-08-27 Thread Thomas Robitaille
Hi,

It seems that the match_original=True option in PatchCollection does not 
preserve line style. Is this deliberate? If not, here is a patch for 
collections.py:

Index: collections.py
===
--- collections.py  (revision 8664)
+++ collections.py  (working copy)
@@ -1041,6 +1041,7 @@
 facecolors   = [determine_facecolor(p) for p in patches]
 edgecolors   = [p.get_edgecolor() for p in patches]
 linewidths   = [p.get_linewidth() for p in patches]
+linestyles   = [p.get_linestyle() for p in patches]
 antialiaseds = [p.get_antialiased() for p in patches]
 
 Collection.__init__(
@@ -1048,7 +1049,7 @@
 edgecolors=edgecolors,
 facecolors=facecolors,
 linewidths=linewidths,
-linestyles='solid',
+linestyles=linestyles,
 antialiaseds = antialiaseds)
 else:
 Collection.__init__(self, **kwargs)

Cheers,

Tom
--
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Issue with Ellipses and PatchCollections

2010-09-01 Thread Thomas Robitaille
>>> I have submitted a ticket: 
>>> https://sourceforge.net/tracker/?group_id=80706&atid=560720
>> 
>> The obvious fix would be to change from patch.fill to
>> patch.get_fill(). However, I'm curious how this code got broken.
> 
> I broke it here: 
> http://currents.soest.hawaii.edu/hgstage/hgwebdir.cgi/mpl_hg/diff/799df584a8df/matplotlib/lib/matplotlib/patches.py
> 
> The safest way to fix it--that is, preserving the old behavior of 
> patch.fill--would be to make it a property.  I can do that later today or 
> tomorrow, or you can go ahead with it.  It would be something of an 
> inconsistency, in that for partly historical reasons mpl is based on an 
> endless procession of getters and setters, but I don't think it would do any 
> harm, and it does preserve the earlier API.  At the same time, it would be OK 
> to use get_fill in the PatchCollection--it will work, and it is more 
> consistent with typical mpl usage.  So, I think the best fix is to make both 
> changes, with a comment in patches.py as to why fill is a property.

I was wondering whether it would be possible at least for now to implement the 
get_fill() fix in PatchCollection? One of the packages I develop 
(http://aplpy.sourceforge.net/) depends on match_original, and recent svn 
versions of matplotlib are unusable because of this.

Thanks!

Tom

> 
> Eric
> 
>> 
>> Eric, any ideas? SVN claims that the last change to that line was done
>> by you (based on a bug *I* reported)? It apparently worked then:
>> 
>> http://sourceforge.net/mailarchive/message.php?msg_name=487A5AE3.5070500%40gmail.com
>> 
>> Ryan
>> 
> 


--
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Bug in pcolormesh with MacOSX backend

2010-10-05 Thread Thomas Robitaille
Hello,

The MacOS X backend does not seem to show lines between cells when using 
pcolormesh. I have submitted a bug report:

https://sourceforge.net/tracker/?func=detail&aid=3081512&group_id=80706&atid=560720

Cheers,

Tom
--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel