John: What I need to do is create drawings of windows (as in
> plug holes in houses and let in light) with grid and other
> options on the fly.
> So what I need are the graphic primitives -- canvas, lines,
> fills ... The output needs to be a graphic file.
You probably want to be using matplotlib primitives. Assuming you
have a matplotlib.axes.Axes (or Subplot) instance stored as "ax", The
matplotlib.lines.Line2D - add with ax.add_line
matplotlib.patches.Rectangle - add with ax.add_patch
matplotlib.patches.Polygon - add with ax.add_patch
matplotlib.patches.RegularPolygon - add with ax.add_patch
matplotlib.patches.Circle - add with ax.add_patch
matplotlib.patches.Text - add with ax.add_artist
Ie, there are not too many mpl primitives, and using these will
insulate you from changes in the mpl backend (renderer) api. The
backend API is meant only for mpl developers. The classes referred to
above are all part of the matplotlib Artist hierarchy.
> I will go back and study the docs, but a suggestion of what
> area to use would be most welcome. Or, of course, a
> different module than matplotlib if that would be more
To reiterate, there is one base class matplotlib.artist.Artist that
all the objects that render into the figure derive from. From this,
there are just a few derived classes to be aware of: Line2D, Patch,
Text, and Collection. From these there are a few more derived classes (eg
Patch and Collection have some specialized derived classes, Line2D and
Text do not as of yet). Other Artists (including Figure, Axes,
Legend, Table and so on) are simply composites of these primitive
types. See the following class docs for more info:
In short, you should concentrate on building the primitive types you
need rather than calling the renderer methods directly. The
primitives will call the right renderer methods as necessary (as they
do in matplotlib.lines, for example).
Hope this helps,