Re: [Matplotlib-users] Problem with pylab.fill

2006-12-06 Thread John Hunter
 Pellegrini == Pellegrini Eric [EMAIL PROTECTED] writes:

Pellegrini Hi everybody, I would like to build an application
Pellegrini where many filled polygons will have to be displayed
Pellegrini on the screen. To do so, I would like to use
Pellegrini matplotlib but, up to now, my application is not fast
Pellegrini enough.

Hmm, I'm not seeing the performance problem on my system -- I can
create and save the figure in a fraction of a second.  Is your numerix
setting set to numpy?  Run the script with --verbose-helpful and send
us the output.

A few things to note: if you really want regular polygons, eg the
squared in your example, do any of the plot markers work for you.

plot(x, marker='s')

will be about as fast as mpl gets.  You can set the marker size with
the markersize property.

Second, if you need arbitrary polygons, and need a lot of them, a
polygon collection will be faster.  I had to bump the number of polys
up to about 8000 to show a dramatic performance difference.

Here are two scripts and performance numbers -- one using fill and one
using a polygon collection

 time python test.py -dAgg
6.595u 0.089s 0:06.68 99.8% 0+0k 0+0io 0pf+0w

 time python test2.py -dAgg
0.565u 0.033s 0:00.59 100.0%0+0k 0+0io 0pf+0w

 cat test.py
import pylab

x = range(0,81000,10)
pylab.axis('off')
for i in range(0,len(x)-1):
pylab.fill([x[i],x[i+1],x[i+1],x[i]],[10,10,20,20])
pylab.axis((0,max(x),0,610))
pylab.savefig('test')
pylab.show()

 cat test2.py
import pylab
from matplotlib.collections import PolyCollection
fig = pylab.figure()
ax = fig.add_subplot(111)
x = range(0,81000,10)

pylab.axis('off')
verts = [((x[i], 10), (x[i+1], 10), (x[i+1], 20), (x[i], 20)) for i in 
range(len(x)-1)]
col = PolyCollection(verts)
ax.add_collection(col)
pylab.axis((0,max(x),0,610))
pylab.savefig('test')
pylab.show()

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] artist.py

2006-12-06 Thread Tom Denniston
Sorry meant to send this to the whole list:


John,

Thanks for the fix.  After reading Eric's email I started to question
my profiling results but I still (without your fix) seem to see a
significant time when in Artist when generating large volumes of
graphs.  I need to rebuild my matplotlib against svn and test your fix
now to see if that solves the problem.

Thanks for your help.


--Tom



On 12/5/06, John Hunter [EMAIL PROTECTED] wrote:
  Christopher == Christopher Barker [EMAIL PROTECTED] writes:

Christopher This sounds like a job for properties! make
Christopher _transform a property, and code that gets and sets it
Christopher directly should still work. though People that were
Christopher accessing an underscored name directly should expect
Christopher this kind of problem.

 The matplotlib artist kwarg properties act like python properties or
 enthought traits, with some advantages and disadvantages over each
 (mostly disadvantages, alas).  We've discussed migrating to one or
 another over the years, but haven't bitten the bullet.  At each point
 it's easier to extend the exiting implementation than refactor the
 whole bit; the tyranny of small decisions.

 Here are some of the pros and cons as I see them of enthought traits
 vs python properties

   Pros:
   * compatibility with the rest of the enthought tool suite
   * built in observer pattern
   * automatic UI for wx users
   * performance is better than python properties last time I looked
   * matplotlib ships with enthought traits built in

   Cons:
   * smaller user base than python properties may imply
 fewer 3rd party enhancements, less support, etc
   * we have to maintain our copy of enthought traits to keep it
 current and building or require an additional dependency

 I spent some time working on matplotlib rc properties as enthought
 traits as a precursor to porting matplotlib properties to traits.
 Here is some example code showing how to define some representative rc
 properties and construct a matplotlib artist using traits.  Because
 matplotlib ships with enthought traits already, you can run this
 script with just matplotlib.  Unfortunately, we do not ship the ex UI
 component so you can't test that part.  I'm  a bit of a traits newbie
 so there are probably better ways to do what I have done below.

 import sys, os, re
 import matplotlib.enthought.traits as traits
 from matplotlib.cbook import is_string_like
 from matplotlib.artist import Artist

 doprint = True
 flexible_true_trait = traits.Trait(
True,
{ 'true':  True, 't': True, 'yes': True, 'y': True, 'on':  True, True: 
 True,
  'false': False, 'f': False, 'no':  False, 'n': False, 'off': False, 
 False: False
   } )
 flexible_false_trait = traits.Trait( False, flexible_true_trait )

 colors = {
'c' : '#00bfbf',
'b' : '#ff',
'g' : '#008000',
'k' : '#00',
'm' : '#bf00bf',
'r' : '#ff',
'w' : '#ff',
'y' : '#bfbf00',
'gold' : '#FFD700',
'peachpuff': '#FFDAB9',
'navajowhite'  : '#FFDEAD',
}

 def hex2color(s):
Convert hex string (like html uses, eg, #efefef) to a r,g,b tuple
return tuple([int(n, 16)/255.0 for n in (s[1:3], s[3:5], s[5:7])])

 class RGBA(traits.HasTraits):
# r,g,b,a in the range 0-1 with default color 0,0,0,1 (black)
r = traits.Range(0., 1., 0.)
g = traits.Range(0., 1., 0.)
b = traits.Range(0., 1., 0.)
a = traits.Range(0., 1., 1.)
def __init__(self, r=0., g=0., b=0., a=1.):
self.r = r
self.g = g
self.b = b
self.a = a
def __repr__(self):
return 'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)'%\
   (self.r, self.g, self.b, self.a)

 def tuple_to_rgba(ob, name, val):
tup = [float(x) for x in val]
if len(tup)==3:
r,g,b = tup
return RGBA(r,g,b)
elif len(tup)==4:
r,g,b,a = tup
return RGBA(r,g,b,a)
else:
raise ValueError
 tuple_to_rgba.info = 'a RGB or RGBA tuple of floats'

 def hex_to_rgba(ob, name, val):
rgx = re.compile('^#[0-9A-Fa-f]{6}$')

if not is_string_like(val):
raise TypeError
if rgx.match(val) is None:
raise ValueError
r,g,b = hex2color(val)
return RGBA(r,g,b,1.0)
 hex_to_rgba.info = 'a hex color string'

 def colorname_to_rgba(ob, name, val):
hex = colors[val.lower()]
r,g,b =  hex2color(hex)
return RGBA(r,g,b,1.0)
 colorname_to_rgba.info = 'a named color'

 def float_to_rgba(ob, name, val):
val = float(val)
return RGBA(val, val, val, 1.)
 float_to_rgba.info = 'a grayscale intensity'



 Color = traits.Trait(RGBA(), float_to_rgba, colorname_to_rgba, RGBA,
  hex_to_rgba, tuple_to_rgba)

 def file_exists(ob, name, val):
fh = file(val, 'r')
return val

 def path_exists(ob, name, val):
os.path.exists(val)
 linestyles  = ('-', '--', '-.', ':', 'steps', 

Re: [Matplotlib-users] REQ: pcolor input similar to array broadcasting

2006-12-06 Thread Eric Firing
Rob,

This is now in svn, for pcolor only, not for pcolormesh.  Please check 
it out.  If everything is OK I can add it to pcolormesh as well 
(although pcolormesh still has a deeply-buried bug such that it does not 
work with alpha != 1).

Eric

Robert Hetland wrote:
 
 I would like to propose expanding the inputs of pcolor to take vectors.  
 Often, you have x and y independent (seperable), and you don't want to 
 go on constructing an x array of redundant values.  Actually, in NumPy 
 it is not straightforward to do this with resize if your variable is in 
 the first dimension like time (well, there is meshgrid, but you would 
 only use it for plotting, and with two vectors -- see below).  Since 
 NumPy makes such heavy use of array broadcasting, it is not necessary.
 
 I think MPL should follow the spirit of array broadcasting, and make it 
 such that:
 
 x = arange(10)
 y = arange(30)
 z = rand(30,10)
 pcolor (x, y, z)
 
 will work as expected.  Perhaps, we could require a NewAxis in the right 
 places, but it would also make sense without. You should also be able to 
 send in just one vector.  Consider
 
 x,y = meshgrid(arange(10), arange(30))
 y = y + random.normal(size=y.shape)
 z = random.random(y.shape)
 pcolor (x, y, z)
 % but x is still essentially just arange(10)
 pcolor(arange(10), y, z)
 
 What do you all think?
 
 -Rob.
 
 
 -
 Rob Hetland, Assistant Professor
 Dept of Oceanography, Texas AM University
 p: 979-458-0096, f: 979-845-6331
 e: [EMAIL PROTECTED], w: http://pong.tamu.edu
 


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] open figures list

2006-12-06 Thread belinda thom
Hello,

Is there a way to return a list of all the open figure numbers? For  
instance, if I had:

close('all')
figure(1)
[some plotting]
figure(5)
[some plotting]

I'd like to be able to have access to a command that returns the list  
[1, 5].

Thanks,

--b

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users