在Matplotlib中缩小视图

4 投票
1 回答
6487 浏览
提问于 2025-04-18 15:00

我有一个表面图,我需要一个特定的视角,正如下面的图片所示:

在这里输入图片描述

现在,你可以看到,我的坐标轴图例的最底部部分缺失了,因为matplotlib把它切掉了。有没有办法通过编程来缩小图像,让所有内容都能适应窗口呢?

这是我最初的代码:

values_all = zip(*values_all)
x = range(len(values_all[0]))
y = range(len(values_all))
figure = plt.figure(1, figsize=(10, 7))
ax = Axes3D(figure, azim=-124, elev=40, zlim=(0, 0.4))
x, y = np.meshgrid(x, y)
surface = ax.plot_surface(x, y, values_all, linewidth=0, rstride=1, cstride=1, cmap=cm.jet)
plt.colorbar(surface, shrink=0.4, aspect=10)
plt.show()

1 个回答

5

调用

 plt.tight_layout()

在此之前

 plt.show()

撰写回答