Drawing lots of lines or polygons

I frequently find myself wanting to draw a bunch of disconnected line segments or polygons.
Is there anything in matplotlib to facilitate that? I usually just end up writing a loop.
Like:
for s,e in izip(starts,ends):

     plot([s[0],e[0]], [s[1],e[1]], 'b-')

Or if the starts and ends are interleaved, something like
for i in enumerate(segs[::2])
plot(segs[i:i+2,0], segs[i:i+2,1], ‘b-’)

For a set of polys it’s much the same just i:i+N instead of i:i+2.

–bb

Bill,

I'm not totally sure if it will help for this, but try checking out

matplotlib.collections.LineCollection
and
matplotlib.collections.PolyCollection

http://matplotlib.sourceforge.net/matplotlib.collections.html

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

That does look like what I’m after. Two things are unclear to me from the docs you pointed to:

  1. How do you actually add something to a plot with those? Are they automatically added to the current figure just by creating them?

  2. How do patch/poly collections determine the edges? All I can see in the docs is a mention of a list of verts, but not any mention of how you specify edges.

Thanks,
–bb

···

On 5/19/07, Christopher Barker <Chris.Barker@…259…> wrote:

Bill,

I’m not totally sure if it will help for this, but try checking out

matplotlib.collections.LineCollection
and
matplotlib.collections.PolyCollection


http://matplotlib.sourceforge.net/matplotlib.collections.html

-Chris


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice

7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@…259…

Bill Baxter wrote:

That does look like what I'm after. Two things are unclear to me from the docs you pointed to:
1) How do you actually add something to a plot with those? Are they automatically added to the current figure just by creating them?

I'm no expert, but it looks like you need to do:
axis.add_collection(YourCollection)

After all, there could be any number of axes on one figure.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Yep, this i the right approach. See the following examples:

collections_demo.py
dynamic_collection.py
lasso_demo.py
line_collection.py
line_collection2.py

···

On 5/18/07, Christopher Barker <Chris.Barker@...259...> wrote:

Bill Baxter wrote:
> That does look like what I'm after. Two things are unclear to me from
> the docs you pointed to:
> 1) How do you actually add something to a plot with those? Are they
> automatically added to the current figure just by creating them?

I'm no expert, but it looks like you need to do:
axis.add_collection(YourCollection)

Great. Thanks for the pointers!

--bb

···

On 5/20/07, John Hunter <jdh2358@...287...> wrote:

On 5/18/07, Christopher Barker <Chris.Barker@...259...> wrote:
>
> I'm no expert, but it looks like you need to do:
> axis.add_collection(YourCollection)

Yep, this i the right approach. See the following examples:

collections_demo.py
dynamic_collection.py
lasso_demo.py
line_collection.py
line_collection2.py