首页 > 解决方案 > matplotlib 中 figure.add_axes() 中的 left 和 bottom 有什么作用?

问题描述

你好,我目前正在学习matplotlib。我刚刚了解了数字和add_axes()方法。对于该add_axes()方法,您传入一个包含[left, bottom, width, height].

显然,width并且height控制了图形的宽度和高度,但是做什么leftbottom做什么呢?

这是我的add_axes()->axes = figure.add_axes([0.1, 0.1, 0.6, 0.6])

我一直在改变leftand bottom,但情节上没有任何改变。我在 上阅读了 matplotlib 文档figure.add_axes(),但它没有解释什么leftbottom做了什么。

谢谢!

标签: pythonmatplotlibfigure

解决方案


mpl.figure.add_axes 的描述和示例

mpl.figure.add_axes(rect, projection=None, polar=False, **kwargs) 

将轴添加到当前图窗或指定轴。
来自matplotlib mpl.figure.ad_axes 方法文档:
rect:浮点序列。新轴的尺寸 [left, bottom, width, height]。所有数量都是图形宽度和高度的分数。

  • left = 距离图形左侧多远(如 ax 值)
  • bottom = 离图形底部多远(如 ay 值)

这是一个快速的谷歌搜索
这是一个例子:

fig, ax1 = plt.subplots(figsize=(12,8))
ax2 = fig.add_axes([0.575,0.55,0.3,0.3])

ax1.grid(axis='y', dashes=(8,3), color='gray', alpha=0.3)
for ax in [ax1, ax2]:
    [ax.spines[s].set_visible(False) for s in ['top','right']]

在此处输入图像描述


推荐阅读