我想用matplotlib中的面板标签("A","B",......")来标注我正在制作的图表.例如,我想要注释一组带有大"A"的子图.图中的左上角如下面的代码所示.如何更改图形画布以使此"A"可见?
f = plt.figure(figsize=(5,5))
plt.subplot(2, 2, 1)
# this "A" is clipped in the plot
plt.annotate("A",
xy = (-0.25, 1.1),
xytext = (-0.25, 1.1),
xycoords = 'axes fraction',
textcoords = 'axes fraction',
fontsize=30)
plt.subplot(2, 2, 2)
plt.subplot(2, 2, 3)
plt.subplot(2, 2, 4)
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
有没有办法在子图的左侧添加"填充",以便将它们推到图的右侧,而不更改figsize参数?并没有重新调整情节?画布上有足够的空间来贴合标签和子图.
添加plt.subplots_adjust():
f = plt.figure(figsize=(5,5))
plt.subplot(2, 2, 1)
# this "A" is clipped in the plot
plt.annotate("A",
xy = (-0.25, 1.1),
xytext = (-0.25, 1.1),
xycoords = 'axes fraction',
textcoords = 'axes fraction',
fontsize=30)
plt.subplot(2, 2, 2)
plt.subplot(2, 2, 3)
plt.subplot(2, 2, 4)
plt.tight_layout()
plt.subplots_adjust(top=0.9)
plt.show()
Run Code Online (Sandbox Code Playgroud)
只是确保不要放在plt.tight_layout后面,plt.subplots_adjust因为这将覆盖更改.
另请参阅此页面调整子图.
| 归档时间: |
|
| 查看次数: |
3916 次 |
| 最近记录: |