Matplotlib - Transforms

Tulika Kshirsagar

10 months ago

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 −
The user land data coordinate system. controlled by the xlim and ylim
The coordinate system of the Axes. (0,0) is bottom left and (1,1) is top right of the axes.
The coordinate system of the Figure. (0,0) is bottom left and (1,1) is top right of the figure
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 −
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 −
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.

Submit Review