绘图区的设置宽度,matplotlib

问题描述 投票:0回答:1

关于这个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

python matplotlib
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.