I just wanted to add a little bit to Jae-Joon's example. I feel like I have to relearn the axes transformations every time I deal with them. Your email reminded me to write things down, and I thought I'd share it, in case others find it useful. Let me know if anything is wrong/unclear.
On Aug 14, 2008, at 4:51 PM, Jae-Joon Lee wrote:
It seems to me that you're confused with the meaning of the transAxes.
It is a transform from the Axes coordinate to the Canvas(?) coordinate.
As far as I can see, what you seemed to want is a transform between
Data coordinate and Axes coordinate, and that would be transScale +
transLimits (from Data to Axes).
trans = (ax.transScale + ax.transLimits).inverted()
# trans = ax.transLimits.inverted() will also work in this case.
and you will get 2.0, 2.0 as you expected.
The "transform" argument should be transAxes still.
ax.text(valx, valy, actualcoords, transform=ax.transAxes)
As far as your original question is concerned, I have little idea what
you are trying to do, so I'll leave that question to others.
On Thu, Aug 14, 2008 at 3:43 PM, Mathieu Leplatre > <leplatre@...287...> wrote:
I am still investigating and I am stuck at converting transAxes values to data.
If my axes goes from 10.0 to 20.0 then transAxes 0.5 should give me 15.0.
This would allow me to compute bar width and space, since I am able to
convert inches to transAxes values.
I tried many combinations of transAxes, transData, ...,
inverse_xy_tup, xy_tup, inverted(), transform(), ... without success
Any ideas please ?
Axes Transformations Tutorial
The new transformations infrastructure is documented in the `new docs`_ (still
in progress...), which talks about transformations *in general*. This document
talks about transforms that are pre-defined attributes of `axes`. The following
explanation is partially stolen from a mailing list reply by Michael Droettboom.
In the following,
the actual `x, y` input data coordinates
the axes coordinates which are `([0, 0], [1, 1])` at `([xmin,ymin], [xmax,
the screen pixel coordinates.
.. _new docs:
scales data to account for nonlinearities (non-affine) in the axis scales,
e.g. log-log and semi-log scales. For example, `transScale.transform` would
convert `x = [1, 10, 100, 1000]` to `[1, 2, 3, 4]` (powers of ten) if the
x-axis is logarithmically spaced.
scales the data to the currently "zoomed" in portion of the data.
`transScale + transLimits`
maps data space to axes space.
maps axes space to figure space.
maps data space to the figure space. `transData` is a composite of
`transScale`, `transLimits`, and `transAxes`. It's the "fast lane" between
the data and the screen.
If you want to draw a dot in the middle of the plot, you know that
>>> x = y = 0.5
in axes space.
Since the default transform for `matplotlib.pyplot.plot` is `transData`, you can
either either change the transform of the plot operation
>>> import matplotlib.pyplot as plt
>>> ax = plt.subplot(111)
>>> ax.plot(, [y], 'ro', transform=ax.transAxes)
Or you can transform the midpoint to data coordinates then plot them
>>> trans_data2axes = ax.transScale + ax.transLimits
>>> trans_axes2data = trans_data2axes.inverted()
>>> mid_point = trans_axes2data.transform([x, y])
>>> x_trans, y_trans = mid_point
>>> ax.plot([x_trans], [y_trans], 'gs')
It's important to note that these are two **very different** approaches. The
first point (red dot) above is always referenced to axes space and will remain
in the center of the plot, even if you change the axes limits (try panning in
On the other hand, the second point (green square) is referenced to the data
space and will move with the data if the axes limits are changed.