The matplotlib package is built on top of a transformation framework to easily move between coordinate systems. Four coordinate systems can be used. The systems are described in brief in the table given below −
Coordinate | Transformation Object | Description |
---|---|---|
Data | ax.transData | The user land data coordinate system. controlled by the xlim and ylim |
Axes | ax.transAxes | The coordinate system of the Axes. (0,0) is bottom left and (1,1) is top right of the axes. |
Figure | fig.transFigure | The coordinate system of the Figure. (0,0) is bottom left and (1,1) is top right of the figure |
display | None | This is the pixel coordinate system of the display. (0,0) is the bottom left and (width, height) is the top right of display in pixels. Alternatively, the(matplotlib.transforms.IdentityTransform()) may be used instead of None. |
Consider the following example −
axes.text(x,y,"my label")
The text is placed at the theoretical position of a data point (x,y). Thus we would speak of "data coords".
Using other transformation objects, placement can be controlled. For example, if the above test is to be placed in the centre of axes coordinate system, execute the following line of code −
axes.text(0.5, 0.5, "middle of graph", transform=axes.transAxes)
These transformations can be used for any kind of Matplotlib objects. The default transformation for ax.text is ax.transData and the default transformation for fig.text is fig.transFigure.
The axes coordinate system is extremely useful when placing text in your axes. You might often want a text bubble in a fixed location; for example, on the upper left of the axes pane and have that location remain fixed when you pan or zoom.