我正在制作一个绘图,我打算使该绘图与最终保存的文件的边缘有一定距离。
我有一个图形,其中有两个子图,我想与边缘保持距离。我目前正在使用NameOfSubplot.set_position来手动指定到每个边缘的距离,但是由于我必须针对不同的图和数字重复此距离,因此需要很长时间才能找到理想的数字。
我可以使用什么代替set_position给子图指定指定的边缘边界? (由于我是这方面的新手,如果您可以为我输入一个子图的确切代码,我将不胜感激)
python
import matplotlib.pyplot as plt
fig1 = plt.figure(figsize=(16,7))
a = [1990,1995,2000,2005,2010]
b = [2.5,2.7,2.8,3,3.1]
ax1 = fig1.add_subplot(121)
box = ax1.get_position()
ax1.set_position([box.x0,box.y0 +.05,box.width * 0.9,box.height * 0.9])
l1 = ax1.plot(a,b,color='red')
ax3 = fig1.add_subplot(122)
box = ax1.get_position()
ax3.set_position([box.x0 +.4,box.width*0.85,box.height*0.85])
l2 = ax3.plot(a,color='cyan')