如何在图的右侧添加填充,等于左边和左轴之间的距离?

时间:2018-05-01 21:08:00

标签: python matplotlib

我试图获得一个已保存图形的输出,其中有两个并排的子图,在图的左侧和右侧具有相等的间距,因此当图中包含该图时一个文件,看起来这些图集中在一起。

enter image description here

换句话说,添加宽度为' a'从图中的右侧到图。

以下是一些示例代码(替换了数据):

import numpy as np
import matplotlib.pyplot as plt


x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

fig, axes = plt.subplots(nrows=1,
                         ncols=2,
                         dpi=220,
                         squeeze=False,
                         figsize=(3.45, 2.1)
)

axes[0][0].plot(x1, y1, 'o-')
axes[0][0].set_ylabel('Damped oscillation')
axes[0][0].set_xlabel('time (s)')
axes[0][1].plot(x2, y2, '.-')
axes[0][1].set_xlabel('time (s)')

for i in [0, 1]:
    x0, x1 = axes[0][i].get_xlim()
    x_diff = x1 - x0
    y0, y1 = axes[0][i].get_ylim()
    y_diff = y1 - y0
    axes[0][i].set_aspect(x_diff / y_diff)
    axes[0][i].tick_params(labelbottom='off', labelleft='off', axis=u'both', which=u'both', length=0)
    axes[0][i].xaxis.labelpad = 7
    axes[0][i].yaxis.labelpad = 7

fig.savefig('clustering.pdf',
            bbox_inches='tight',
            pad_inches=0,
            dpi='figure')

0 个答案:

没有答案
相关问题