pso*_*res 2 python django matplotlib
我在网上看到很多帖子和答案试图回答这个问题。
然而,使用bbox_inches = 'tight'图例消失了。
这是我的数字之一:

由于我在图框之外有图例,因此我想仅删除顶部和底部的空白区域。
有人知道如何至少删除顶部空白吗?
多谢!
你尝试过使用subplots_adjust()吗?例如,请参阅@DaveP对此问题的回答:Reduce left and right margins in matplotlibplot
另外,看看@Tian Chu 对同一问题的回答。
编辑:这对我有用:
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3],[5,6,7],'gs-')
plt.subplots_adjust(top=0.99, right=0.99)
plt.show()
Run Code Online (Sandbox Code Playgroud)