Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在不使用“设置位置”的情况下从边调整打印框?_Python_Python 3.x_Matplotlib_Plot - Fatal编程技术网

Python 如何在不使用“设置位置”的情况下从边调整打印框?

Python 如何在不使用“设置位置”的情况下从边调整打印框?,python,python-3.x,matplotlib,plot,Python,Python 3.x,Matplotlib,Plot,我正在制作一个绘图,我打算使该绘图与最终保存文件的边缘保持一定距离 我有一个图,其中我有两个子图,我想知道与边缘的距离。我目前正在使用NameOfSubplot.set_position来手动给出距离每条边的距离,但由于我必须为不同的图和数字复制此值,因此需要很长时间才能找到完美的数字 我可以使用什么来代替设置_位置来为子地块指定边边界? (由于我对这一切都不熟悉,如果您能为我键入一个子批次的准确代码,我将不胜感激) python import matplotlib.pyplot as plt

我正在制作一个绘图,我打算使该绘图与最终保存文件的边缘保持一定距离

我有一个图,其中我有两个子图,我想知道与边缘的距离。我目前正在使用NameOfSubplot.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.y0 +.05, box.width*0.85, box.height*0.85])    
l2 = ax3.plot(a, b, color='cyan')
按重要性排序的解决方案


例如,如果图形宽度为16英寸,并且您希望两侧都有一英寸的填充,则可以设置:

fig1.subplots_adjust(left=1/16, right=15/16)
用户添加12321257:

如果我们也需要顶部和底部的间距,它将是这样的(假设图宽16英寸,高7英寸):


例如,如果图形宽度为16英寸,并且您希望两侧都有一英寸的填充,您可以设置
fig1。子图\u adjust(left=1/16,right=15/16)
谢谢您的简明回答。这是我一直在寻找的,而且很容易理解。我想补充一点,如果我们也想要从顶部和底部的间距,它将是这样的(假设图形是16英寸宽,7英寸高):
python
fig1.subplot\u adjust(左=1/16,右=15/16,底部=1/7,顶部=6/7)@user12321257,好吧,谢谢你的重要性。这是一篇维基文章,请随意编辑。
fig1.subplots_adjust(left= 1/16, right= 15/16, bottom = 1/7, top = 6/7)