tho*_*hor 6 python matplotlib figure python-2.7 subplot
我正在使用Matplotlib并努力在我正在绘制的包含一个子图网格的图形周围获得恰当数量的空白.
要求:能够选择所有子图的纵横比(它们都是相同的),准确定义子图与(保存的)图边缘的顶部,底部和左侧之间有多少空白.我右边不需要任何额外的空间.
我到目前为止的代码包含以下内容:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(ncols=6, nrows=2, sharex=True,
sharey=True, figsize=(16,8))
axes[0,0].plot(x,y)
etc...
plt.subplots_adjust(hspace=1.0, wspace=0.02, bottom=0.17, left=0.075, top=0.18)
plt.savefig('Fig1_matplot.pdf', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
实际上,如果我没有指定子图figsize=()的宽高比是错误的.如果我这样做,那么只要我更改参数,宽高比就会改变subplots_adjust().显然left cannot be >= right和bottom cannot be >= top.如果我将top定义为除0以外的任何值,它会将所有子图完全压缩到图底部的一条线.
如果我指定bbox_inches='tight'然后它会在底部和左侧切断我定义的空格,但如果我没有指定它,那么我在右边留下了多余的空格,因为我无法摆脱它(右边是<=剩下).
我有点卡住,任何帮助都会非常感激.
干杯.
小智 18
当使用subplots_adjust,的值left,right,bottom和top如该图的宽度和高度的级分被提供.此外,所有值都是从图的左边和底边测量的.这就是为什么right,top也不能低于left和bottom.典型的设置是:
plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
Run Code Online (Sandbox Code Playgroud)
另一方面,如果要以英寸为单位提供空白作为绝对值,则必须除以图形的宽度和高度.例如,在您的情况下,可以通过以下方式实现所有边缘周围1英寸的边距:
plt.subplots_adjust(left=1/16.0, right=1-1/16.0, bottom=1/8.0, top=1-1/8.0)
Run Code Online (Sandbox Code Playgroud)
为了更多功能,我通常将图的宽度和高度参数化为:
figw, figh = 16.0, 8.0
fig, axes = plt.subplots(ncols=6, nrows=2, sharex=True, sharey=True,
figsize=(figw, figh))
plt.subplots_adjust(left=1/figw, right=1-1/figw, bottom=1/figh, top=1-1/figh)
Run Code Online (Sandbox Code Playgroud)
的hspace和wspace作为一个面板的轴的级分的宽度和被计数的高度,使得它们的绝对值依赖于图中的尺寸,所述外边缘和副区的数量,这将需要进行微调多点点数学.
| 归档时间: |
|
| 查看次数: |
6570 次 |
| 最近记录: |