设置绘图区域的宽度,matplotlib

时间:2019-02-06 08:19:04

标签: python matplotlib

此pyplot图表右侧的文本被剪切,如何在不更改x轴的情况下扩展绘图区域?

最少的示例代码(与示例图片相似但不相同)

import numpy as np

import matplotlib.pyplot as plt
import matplotlib as mp

n40=146-1.07*40
n90=146-1.07*90 
ageAxis =np.array([10, 40, 90])
Normal=np.array([n40, n40, n90])
plt.plot(ageAxis,Normal)

plt.text(90.2,50,'long text here that will be clipped')
ax = plt.gca()
ax.set_ylim([0,165])
ax.set_xlim([0,90])
fig= plt.gcf()
# set size fig.set_size_inches(20, 10.5)
plt.show()

pyplot

1 个答案:

答案 0 :(得分:0)

似乎可以通过set_size_inches和subplots_adjust的组合来完成

我认为它并不优雅,但可以:

import numpy as np

import matplotlib.pyplot as plt
import matplotlib as mp

n40=146-1.07*40
n90=146-1.07*90 
ageAxis =np.array([10, 40, 90])
Normal=np.array([n40, n40, n90])
plt.plot(ageAxis,Normal)

plt.text(90.2,50,'long text here that will be clipped')
ax = plt.gca()
ax.set_ylim([0,165])
ax.set_xlim([0,90])
fig= plt.gcf()
fig.set_size_inches(10, 5.5)     # set a suitable size
plt.subplots_adjust(right=0.75)  # adjust plot area
plt.show()