figure.add_axes()中的左侧和底部在Matplotlib中做什么?

2024-09-30 22:14:36 发布

您现在位置:Python中文网/ 问答频道 /正文

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

显然,widthheight控制图形的宽度和高度,但是leftbottom做什么呢

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

我一直在改变leftbottom,但绘图上没有任何变化。我阅读了关于figure.add_axes()的matplotlib文档,但它没有解释leftbottom做了什么

谢谢大家!


Tags: 方法add图形列表宽度高度matplotlib数字
1条回答
网友
1楼 · 发布于 2024-09-30 22:14:36

mpl.figure.add_轴的说明和示例

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

将轴添加到当前图形或指定轴。
matplotlib mpl.figure.ad_axes method documentation:
rect:浮点数的顺序。新轴的尺寸[左、下、宽、高]。所有数量均以图形宽度和高度的分数表示

  • left=距离图形左侧的距离(如x值)
  • 底部=距离图形底部的距离(如y值)

Here is a quick google search
以下是一个例子:

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']]

enter image description here

相关问题 更多 >