Python-matlibplot-控制图形尺寸

时间:2018-11-11 17:04:20

标签: python

在使用matlibplot时,在控制图形尺寸方面存在一些问题。我希望该图的尺寸准确为9厘米* 14.5厘米。我使用“ figsize”命令来控制图形尺寸;但是,该数字超出了指定的大小。请告知如何实现此目标。

python代码如下:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize = (9/2.54, 14.5/2.54), nrows = 2, ncols = 1)
ax[0] = plt.subplot(2, 1, 1)

x1 = [30, 40, 50, 60, 70, 80, 90, 100]
y1 = [6, 7, 8, 9, 10, 11, 12, 13]

ax[0].plot(x1, y1, 'r-s', label = 'XXXXXXXX')
ax[0].set_xlabel('Percentage load (%)')
ax[0].set_ylabel('Output parameter (%)')
ax[0].legend(loc = (0.05, 0.8))
ax[0].text(0.05, 0.7, '(a)', transform = ax[0].transAxes)
ax[0].set_xlim(x1[0], x1[-1])

x2 = [30, 40, 50, 60, 70, 80, 90, 100]
y2 = [6, 7, 8, 9, 10, 11, 12, 13]
ax[1] = plt.subplot(2, 1, 2)
ax[1].plot(x2, y2, 'k-o', label = 'YYYYYYYYY')
ax[1].set_xlabel('Percentage load (%)')
ax[1].set_ylabel('Output parameter (%)')
ax[1].legend(loc = (0.05, 0.8))
ax[1].text(0.05, 0.7, '(b)', transform = ax[1].transAxes)
ax[1].set_xlim(x2[0], x2[-1])

plt.subplots_adjust(top=1, bottom=0.0, left=0.0, right=1, hspace=0.2, wspace=0.0)

plt.savefig(fname = '2figax.png', dpi = 600, quality = 95, bbox_inches = 'tight', pad_inches = None)

0 个答案:

没有答案