擅长:python、mysql、java
<p>我看起来默认情况下,mplot3d会在一个非常高的地块的顶部和底部留下相当大的空间。但是,您可以使用<code>fig.subplots_adjust</code>技巧来填充该空间,并将顶部和底部扩展到正常绘图区域之外(即<code>top > 1</code>和<code>bottom < 0</code>)。对于你的特殊情节,这里可能需要一些尝试和错误。</p>
<p>我为x、y和z创建了一些随机数组,其限制与您的图类似,并且发现下面的参数(<code>bottom=-0.15</code>,<code>top = 1.2</code>)似乎工作正常。</p>
<p>您可能还需要更改<code>ax.view_init</code>以设置一个良好的视角。</p>
<pre><code>import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from numpy import random
# Make some random data with similar limits to the OP's example
x,y,z=random.rand(3,100)
z*=250
y*=800
y+=900
x*=350
x+=1200
fig=plt.figure(figsize=(4,35))
# Set the bottom and top outside the actual figure limits,
# to stretch the 3D axis
fig.subplots_adjust(bottom=-0.15,top=1.2)
ax = fig.add_subplot(111, projection='3d')
# Change the viewing angle to an agreeable one
ax.view_init(2,None)
ax.scatter(x, y, z, zdir='z', c= 'red')
plt.savefig("plot.png")
</code></pre>
<p><img src="https://i.stack.imgur.com/NNq3D.png" width="200"/></p>