how to plot a Polygon / plt.draw() problem

Thank you very much, you helped me a great deal. The video tutorials are great.

I'm going through the stuff you sent and things seem to become clearer....



----- Original Message -----
From: John Hunter
Sent: 04/11/10 04:19 PM
To: tomislav_maric@...2537...
Subject: Re: [Matplotlib-users] how to plot a Polygon / plt.draw() problem

On Sun, Apr 11, 2010 at 7:15 AM, tomislav_maric@...2537... <tomislav.maric@...2537...> wrote:

can someone help me to plot a polygon in matplotlib?

I have been reading about the axes.patches.Polygon class and I have defined

Polygon object that has a preset lw and points. How do I plot it?

I'm confused because the Axes documentation states that this class holds
most of

the figure objects like Rectangle, Line2D, and then the website states that
the Line2D

is a return object from the plt.plot() invocation.

Yes, Axes.plot is a helper function which creates a Line2D object,
adds it to the axes, sets the transformation, etc... This process is
covered in some detail in the matplotlib Artist tutorial

and in the advanced matplotlib tutorial at scipy -- video available here

SciPy 2009 - Advanced tutorial 3: Advanced topics in matplotlib : Free Download, Borrow, and Streaming : Internet Archive

What if I create my own
set of Rectangle

(Polygon) objects and want to create a list of them and plot them?

If you create your own polygons/rectangles/patches, create them, and
then add them with Axes.add_patch

If you want to create a bunch of them, consider a PolygonCollection
(or a RegularPolygonCollection depending on your use case)
Search — Matplotlib 3.8.2 documentation

Also, I'm using this sequence of commands to work in OO mode interactively

(just to learn) but when I execute plt.draw() no figure appears.

We make a distinction between raising a figure ( and
rendering to an existing figure (plt.draw). In interactive mode
(which is what ipython -pylab turns on) figures are automatically
raised/shown. You can control these settings from a regular python
shell using ion and ioff. See

Here is a complete example::

import matplotlib.patches as patches
import matplotlib.pyplot as plt

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

verts = [0,0], [0,1], [1,1], [1,0]

poly = patches.Polygon(verts)



Hope this helps,