简体   繁体   English

Matplotlib:我们如何控制图形边框和轴边框相对于图形以及多个轴之间的填充?

[英]Matplotlib: How do we control figure border and axes borders padding with respect to figure and between multiple axes as well?

Unable to control figure border and axes borders padding with respect to figure and between multiple axes as well using fig.add_axes or plt.subplot_adjust无法使用 fig.add_axes 或 plt.subplot_adjust 控制图形边框和轴边框相对于图形和多个轴之间的填充

Code:

import matplotlib.pyplot as plt8

`axs=[] 
fig=plt8.figure(figsize=(6.0,4.0),edgecolor='red',linewidth=10,dpi=100) 
print(fig)   
ax1=fig.add_axes([0.6,1,2.0,1.5])
axs+=[ax1]
ax2=fig.add_axes([3.3,1,2.0,1.5])
axs+=[ax2]`

Description:

This is figsize=(6.0,4.0) As per co-ordinates given by me, I want to have 2 rectangle plots inside the above figure这是 figsize=(6.0,4.0) 根据我给的坐标,我想在上图中有 2 个矩形图

Gap between the 2 plots is 0.7 and width=2.0 for both plots height=1.5 for both plots left pad with respect to figure is 0.6 right pad is 1.1 top pad is 1.5 bottom pad is 1两个地块之间的间隙为 0.7,两个地块的宽度 = 2.0 两个地块的高度 = 1.5 相对于图形的左垫为 0.6 右垫为 1.1 上垫为 1.5 下垫为 1

But this is not working , can anyone suggest solution code ?

The dimensions you use when calling add_axes() need to be fractions of the figure (see here ).调用add_axes()时使用的尺寸需要是图形的分数(参见此处)。

The tuple required is "(left, bottom, width, height)".所需的元组是“(left, bottom, width, height)”。

Therefore:所以:

ax1=fig.add_axes([0.6/6.0, 1.0/4.0, 2.0/6.0, 1.5/4.0])
ax2=fig.add_axes([3.3/6.0, 1.0/4.0, 2.0/6.0, 1.5/4.0])

Dividing by 6.0, for left position and width, given that you specify 6.0 as figure width.除以 6.0,对于左侧位置和宽度,假设您将 6.0 指定为图形宽度。 Dividing by 4.0, for bottom position and height, given you specify 4.0 as your figure height.除以 4.0,得到底部位置和高度,假设您指定 4.0 作为图形高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM