Matplotlib pyplot show未调整大小以适应figu

2024-04-20 09:29:49 发布

您现在位置:Python中文网/ 问答频道 /正文

从联机阅读(比如here,尽管他们导入pylab而不是pyplot,我从中得到了相同的结果),当使用pyplot的show方法时,如果图形被放置在主图之外,它应该自动重新缩放图形以包括图例;但是,这似乎不会发生在我的代码中。在

有人知道怎么做吗?谢谢。在

# Cut down example of graph drawing, with cut-off legend

plt.xlim([0,1])
plt.ylim([0,1])

line_x = line[t2][0::2]
line_y = line[t2][1::2]

plt.plot(line_x, line_y, label="Line")

plt.grid("on")
plt.tight_layout()
plt.legend(bbox_to_anchor=(1.01, 0.5), loc="center left")

plt.show()

Graph with cut-off legend


Tags: 方法代码图形hereshowlineplt联机