 # plotting directly using the renderer

Hello everyone, Hello John,

> thank you very much for your example - it is really
> fantastic. This was exactly what I meant.

> When I was trying to rewrite your code to a
> 'fastplot()'-command (which would just be able to plot one
> point at a time) it worked quite well with the
> Circle()-command you used. But is there a possibility to
> write the 'fastplot' in a way so that it can be used like
> fastplot(x,y, marker='s', color='g',markersize = 3)?

This approach can work, but may not be as fast as possible since there
is more machinery in Line2D than you need (eg the sequence stuff, the
optional linestyle) and logically what you are doing is creating a
polygon. One option would be to create a polygon factory function or
class which parses a marker string and creates the Polygon instance
you want for your marker. You could lift the logic from Line2D, eg

markerd = {
. : _make_point,
, : _make_pixel,
o : _make_circle,
v : _make_triangle_down,
...snip
}

where, for example _make_triangle_down is a stripped down version of
matplotlib.lines.Line2D._draw_triangle_down

def _make_triangle_down(size):
return ( (-size, size),
(size, size),
(0, -size))

you could then create the polygon as I did in my original example code

# this is just a sketch and not complete code, eg you will want to
# compute size appropriately as in the previous example
def polygon_factory(marker, **kwargs)
func = markerd[marker]
verts = func(size)

trans = identity_transform()
trans.set_offset( (x, y), ax.transData)
poly = Polygon( verts, transform=trans, **kwargs )
poly.set_clip_box(ax.bbox)
return poly

You could then use this function like

poly = polygon_factory('s', facecolor='blue', linewidth=2)

If you wanted full parsing of matplotlib format strings (eg 'go' for
green circle) which includes both color and marker, you can use
matplotlib.axes._process_plot_format or a variant of it.

> In the example given below the color is not recognized
> correctly. Do I use Line2D in a wrong way?

Line2D has both an a linestyle and a marker (eg you can pcreate a
single line instance which is 'ro--' (red dashed line with circle
markers). "color" and "linewidth" control the linestyle properties.
"markerfacecolor, ""markeredgecolor", and "markeredgewidth" control
the marker properties. Again, this illustrates why a Line2D object is
a bit too heavy for your needs. The polygon factory function would be

> A second question aims on the running-behavior: It - well
> - stumbles a little bit. If you add a print i to the
> for-loop you can see that the counting is done very
> smoothly. But the plot isn't (at least at my computer -

As I've pointed out before (eg at the animation wiki
http://www.scipy.org/wikis/topical_software/Animations), the pylab
animation technique is for simple throw-away animations. To produce
nice animations, you need to use your GUI timer or idle function
handling. Eg, if I remove your ion, ioff calls and replace your
update functionality with

def update(*args):
i = update.cnt
fastplot_points( x[i], y[i],marker='s',color='r')
update.cnt +=1
if update.cnt<1000: return True
else: return False
update.cnt = 0

tend = time.time()
print 'It took %4.2f s.'%(tend - tstart)

import gobject