Single Point Stored Plot

Hello John & NG,

    thank you very much for your answer. I had
actually make it working using Line2D instances for every point in the
plot (every well location has its own Line2D object associated). It
works reasonably well, but I have some doubts about my
First of all, I don't know how actually *delete* a
Line2D from the plot (when the well should be hidden) and, moreover,
when I have a large number of wells it takes quite a long time to
create all the Line2D instances and plot them...
Do you think it will
work faster/better if I use a RegularPolyCollection?

Thank you very
much for your suggestions.




Date: 18-Apr-2006 16:16


Cc: <matplotlib->

Subj: Re: [Matplotlib-users] Single Point

Stored Plot

"andrea" == andrea gavana@...784... it

<andrea_gavana@...517...> writes:

   > Hello NG, I am facing a

small problem for which I was

   > unable to find a solution.

Basically, I have to make a

   > scatter plot of x, y

coordinates (they represents oil

   > wells positions) on a 2D

map, but I have some constraints:

   > 1) I would like to

have each point as a separate "plot

   > object", because the

user may decide to hide/show only a

   > particular well, or

show/hide them all, or show/hide

   > whatever combination of

wells. 2) At the moment when the

   > class that holds a

single well position/status is created,

   > the plot window

may not be there (because is the user that

   > decides when to

open a new plot window).

   > I have tried something like:

Hey Andrea, sorry for the delay. This is a neat problem and one that
collections were designed to solve. You probably want to use a
RegularPolyCollection rather than a PolyCollection (the latter is for
arbitrary polygons and you must compute all the vertices yourself).
Here is an example that allows you to add and delete markers -- it
inserts them with random positions and colors. You should be able to
adapt it to your application quite easily.

import random

matplotlib.colors import colorConverter

from matplotlib.collections

import RegularPolyCollection

import as cm
from pylab

import figure, show, nx

fig = figure()
ax = fig.add_subplot(111,

xlim=(0,1), ylim=(0,1), autoscale_on=False)

ax.set_title("Press 'a' to

add a point, 'd' to delete one")

# a single point
offsets =


facecolors = [cm.jet(0.5)]

collection =


   numsides=5, # a pentagon


   facecolors = facecolors,

edgecolors = (colorConverter.to_rgba('black'),),

   linewidths =


   offsets = offsets,
   transOffset = ax.transData,


def onpress(event):

press 'a' to add a random point from the collection, 'd' to delete one

   if event.key=='a':
       x,y = nx.mlab.rand(2)
       color = cm.jet(nx.mlab.rand())


       N = len(offsets)
       if N>0:

ind = random.randint(0,N-1)





mpl_connect('key_press_event', onpress)


----Original Message----