>>>>> "Jos=E9" =3D=3D Jos=E9 Alexandre Nalon <nalon@...> writes:
Jos=E9> That, and setting the x_lim inverted, worked as I wanted,
Jos=E9> But one more thing: while I was searching for a specific
Jos=E9> command to do that, I found something (but not much) about
Jos=E9> transforms, which I couldn't exactly understand what they do
Jos=E9> and how they work, but they might be handy in the near
Jos=E9> future. What are they exactly, and how can they help?
The official documentation is at
http://matplotlib.sf.net/matplotlib.transforms.html , but this may be
of limited help because it is not a tutorial.
matplotlib is divided conceptually into three parts: the "matlab
interface" which are the plot functions that most people use and see,
the object oriented "artists" which are classes that store the figure
information and the "backends" which actually put the ink on the paper.
The "artists" are things like lines, text, rectangles, images and so
on, and all of them are concrete classes derived from
matplotlib.artist.Artist. Stupid name, I know, but I'm weak when it
comes to naming. There are, at a minimum, two coordinate systems to
consider when you plot, the "world" coordinates, ie your data
coordinates, and the display coordinates, which are physical locations
on the display device. The mapping between these two is given by a
matplotlib transformations generally store the information about the
data coordinates and display coordinates, and possibly also a
nonlinear function (eg, polar, log). Every artist stores it's own
transform, and you can place different artists in the figure using
different coordinate systems (transforms).
The vast majority of all plot commands use the default data->display
transform and this is invisible in normal usage. But for convenience
and internal usage, matplotlib provides a couple of extra
transformations that you can make use of. For example, suppose you
wanted to place a rectangle in the middle of the axes that was 25%
from the left, bottom, top and right. You would place this rectangle
in the axes in what I refer to as axes coordinates, where 0 is the
left side of the axes, 1 is the width, 0.5 is the middle and so on.
This hypothetical rectangle has left, bottom=3D0.25, 0.25 and width,
from matplotlib.matlab import *
from matplotlib.patches import Rectangle
ax =3D subplot(111)
trans =3D ax.transAxes
r =3D Rectangle( (0.25, 0.25), 0.5, 0.5, transform=3Dtrans)
Likewise, the figure instance provides a default transformation to
allow you to place objects in figure coordinates, where 0,0 is the
bottom left of the figure, 0.5, 0.5 is the middle and 1,1 is the upper
Internally, I use this all the time. For example, I may want to place
the x-ticklabels a few points under the bottom of the y location of
the x-axis, and I have a transformation that allows me to do this with
minimal coding overhead in the presence o figure resizing, dpi
These are examples of the transformations that are provided by
default, and they tend to cover most of the things people want to do.
But if you want to do something more, you can use affine
transformation (matplotlib.transforms.Affine) or otherwise and set
this for a given artist to place the object into the figure as you
The example examples/alignment_test.py in the matplotlib src
distribution makes heavy use of placing text in axes coordinates, so
you may want to take a look at this for an example.