Problem with pylab.fill

Hi everybody, I would like to build an application

    > where many filled polygons will have to be displayed
    > on the screen. To do so, I would like to use
    > matplotlib but, up to now, my application is not fast
    > 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()

Hi John,

thank you very much for the hand.

I think that I have found my mistake. I was launching my script trough “Idle” that seems to be the reason why it was to slow. Running my script with the command line or by double-clicking on it gave results similar to yours. Would you know why Idle application slows down so much the execution of my script ?

By the way, using the Collection class, would you have any idea how to set different colors to the polygons ? Using set_color method change the color of all the plygons.

Thanks again

Eric

John Hunter <jdhunter@…4…> a �crit :

···

“Pellegrini” == Pellegrini Eric
writes:

Hi everybody, I would like to build an application
where many filled polygons will have to be displayed
on the screen. To do so, I would like to use
matplotlib but, up to now, my application is not fast
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()


D�couvrez une nouvelle fa�on d’obtenir des r�ponses � toutes vos questions ! Profitez des connaissances, des opinions et des exp�riences des internautes sur Yahoo! Questions/R�ponses.

I forgot to send the output of the python test.py --verbose-helpful. Perhaps you will find something wrong there. Here it is:

################################"

matplotlib data path C:\Python24\lib\site-packages\matplotlib\mpl-data
$HOME=C:\Documents and Settings\Eric
CONFIGDIR=C:\Documents and Settings\Eric.matplotlib
loaded rc file C:\Python24\lib\site-packages\matplotlib\mpl-data\matplotlibrc
matplotlib version 0.87.6
verbose.level helpful
interactive is False
platform is win32
numerix numpy 1.0rc1
font search path [‘C:\Python24\lib\site-packages\matplotlib\mpl-data’]
loaded ttfcache file C:\Documents and Settings\Eric.matplotlib\ttffont.cache
backend TkAgg version 8.4
########################################"

Thanks again

Eric

John Hunter <jdhunter@…4…> a
�crit :

···

Hi everybody, I would like to build an application
where many filled polygons will have to be displayed
on the screen. To do so, I would like to use
matplotlib but, up to now, my application is not fast
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()


D�couvrez une nouvelle fa�on d’obtenir des r�ponses � toutes vos questions ! Profitez des connaissances, des opinions et des exp�riences des internautes sur Yahoo! Questions/R�ponses.