【问题标题】:enlarging the figure in the pop-out window in matplotlib在 matplotlib 的弹出窗口中放大图形
【发布时间】:2016-01-24 18:48:19
【问题描述】:

如何放大弹出窗口内的图形?我使用以下代码生成我的图:

self._fig = plt.figure()
#self._fig = plt.figure(figsize=(2,1)) # tried this, didn't work, only change the size of the pop-out window, but now the figure itself
ax1 = self._fig.add_subplot(211,projection='3d')

# some code for plotting the lines and drawing the spherical surfaces, which is not shown here

ax1.set_xlim(-6,6)
ax1.set_ylim(-6,6)
ax1.set_zlim(-15,15)
ax1.set_aspect(2.5, 'box') # the axis limit and aspect limit is chosen so that the whole figure has the same scale in all directions
#ax1.view_init(elev=90, azim=0)

ax1.set_xlabel('X-axis')
ax1.set_ylabel('Y-axis')
ax1.set_zlabel('Z-axis')  
ax1.grid(True)

你可以看到弹窗里面有很多未使用的空间,而且这个数字看起来真的很小。我想最大化图形的大小,以便它填满整个弹出窗口。现在即使我手动放大弹窗,图还是一样的。

我尝试改变轴限制,但它似乎不起作用。我尝试设置 figsize 在第一行,但它只改变弹出窗口的大小,但图形本身。

另一个问题是我想改变图形的“相机视图”,使 z 轴(孤轴)是水平的。同样,我在 ax.view_init 中尝试了一系列不同的值,但我无法获得我想要的视图。我只允许我绕 z 轴旋转,而我需要做的是绕 x 或 y 轴旋转 90 度。

【问题讨论】:

  • 什么版本的mpl?你的意思是要创建一个 2x1 的坐标轴网格吗?
  • 对不起,我不明白你的意思。什么是mpl? 2x1 网格轴是什么意思?我想要的只是让这个 3d 图形在弹出窗口中显得更大,而不是像附图所示那样留下这么多的空白空间。
  • ax1 = self._fig.add_subplot(211,projection='3d') 将轴添加到图中作为 2x1 网格的第一个轴。试试self._fig.add_subplot(111,projection='3d')
  • 它有效。太感谢了!但是将整个图形旋转 90 度呢?现在它确实填满了弹出窗口的大部分,但由于图形沿 z 轴较长,因此将 z 轴沿水平方向对齐会好得多。我在 ax.view_init 中尝试了许多不同的值,但都没有给出想要的结果。

标签: python matplotlib plot 3d figure


【解决方案1】:

尝试拨打plt.tight_layout()

在您致电plt.show()之前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2019-07-28
    • 2023-03-06
    • 2021-07-28
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    相关资源
    最近更新 更多