📜  Matplotlib-变换

📅  最后修改于: 2020-11-08 07:30:57             🧑  作者: Mango


matplotlib软件包建立在转换框架之上,可轻松在坐标系之间移动。可以使用四个坐标系。在下表中简要描述了系统-

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.

考虑以下示例-

axes.text(x,y,"my label") 

文本放置在数据点(x,y)的理论位置。因此,我们将谈到“数据坐标”。

使用其他转换对象,可以控制放置。例如,如果要将上述测试放置在轴坐标系的中心,请执行以下代码行:

axes.text(0.5, 0.5, "middle of graph", transform=axes.transAxes)

这些转换可用于任何种类的Matplotlib对象。对于ax.text默认的转换是ax.transDatafig.text默认的转换是fig.transFigure。

在轴上放置文本时,轴坐标系非常有用。您可能经常希望在固定位置放置文本提示框;例如,在“轴”窗格的左上方,并且在平移或缩放时使该位置保持固定。