转换方法 transFigure 如何放置我的文本?
How does the transform method transFigure place my text?
我无法理解 Matplotlib 图中文本位置的不同变换。存在三个预定义的转换:
ax.transData
、ax.transAxes
、fig.transFigure
当我有以下代码时:
fig, ax = plt.subplots(facecolor='lightgray')
ax.axis([0, 10, 0, 10])
ax.text(1, 5, ". Data: (1, 5)", transform=ax.transData)
ax.text(0.2, 0.2, ". Figure: (0.2, 0.2)", transform=fig.transFigure)
第四行我没看懂。第一个问题:我情节中的 figsize 是多少?
我检查了 plt.figure
的文档字符串,它说默认的 figsize 是 6.4(以英寸为单位的宽度)和 4.8(以英寸为单位的高度)。但是当我使用 fig.get_figwidth
和 fig.get_figheight
时,我看到宽度是 6.0 和宽度 4.0。为什么?
假设 figsize 是 (6, 4):
文本应出现在图形大小(x 坐标)的 20% 和图形大小(y 坐标)的 20% 处。
对吗?
I checked the docstring of plt.figure and there it says that default figsize is 6.4 (width in inches) and 4.8 (height in inches).
确实,您可以查看 the source code,其中显示 [6.4, 4.8]
。
But when I use fig.get_figwidth and fig.get_figheight I see that width is 6.0 and width 4.0. Why?
因为您、您使用的解释器或您加载的另一个库更改了这些设置。
Assuming figsize is (6, 4): The text should appear at 20% of figsize (x-coordinate) and 20% of figsize (y-coordinate). Is that correct?
是的,没错。坐标从图的左下角开始。
我无法理解 Matplotlib 图中文本位置的不同变换。存在三个预定义的转换:
ax.transData
、ax.transAxes
、fig.transFigure
当我有以下代码时:
fig, ax = plt.subplots(facecolor='lightgray')
ax.axis([0, 10, 0, 10])
ax.text(1, 5, ". Data: (1, 5)", transform=ax.transData)
ax.text(0.2, 0.2, ". Figure: (0.2, 0.2)", transform=fig.transFigure)
第四行我没看懂。第一个问题:我情节中的 figsize 是多少?
我检查了 plt.figure
的文档字符串,它说默认的 figsize 是 6.4(以英寸为单位的宽度)和 4.8(以英寸为单位的高度)。但是当我使用 fig.get_figwidth
和 fig.get_figheight
时,我看到宽度是 6.0 和宽度 4.0。为什么?
假设 figsize 是 (6, 4):
文本应出现在图形大小(x 坐标)的 20% 和图形大小(y 坐标)的 20% 处。
对吗?
I checked the docstring of plt.figure and there it says that default figsize is 6.4 (width in inches) and 4.8 (height in inches).
确实,您可以查看 the source code,其中显示 [6.4, 4.8]
。
But when I use fig.get_figwidth and fig.get_figheight I see that width is 6.0 and width 4.0. Why?
因为您、您使用的解释器或您加载的另一个库更改了这些设置。
Assuming figsize is (6, 4): The text should appear at 20% of figsize (x-coordinate) and 20% of figsize (y-coordinate). Is that correct?
是的,没错。坐标从图的左下角开始。