matplotlib z轴标签未显示在3D图中

taor4pac  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(266)

我有一个3D图的问题,在可视化它的时候。它没有z轴标签,

但当我设置一个较长的标题时,它会显示:

有没有什么方法可以在不修改标题的情况下“看到”z轴标签,或者有其他解决方案?
这是我的代码:
mask1、mask2、mask3形状为(100,100),值分别为20、32、49

fig = plt.figure(figsize=(12, 4))
ax = fig.add_subplot(projection='3d')
x, y = np.meshgrid(np.arange(100)*20, np.arange(100)*20)
s1 = ax.plot_surface(x, y, mask1*20, linewidth=0, label='Reflector 1')
s1._facecolors2d = s1._facecolor3d
s1._edgecolors2d = s1._edgecolor3d
s2 = ax.plot_surface(x, y, mask2*20, linewidth=0, label='Reflector 2')
s2._facecolors2d = s2._facecolor3d
s2._edgecolors2d = s2._edgecolor3d
s3 = ax.plot_surface(x, y, mask3*20, linewidth=0, label='Reflector 3')
s3._facecolors2d = s3._facecolor3d
s3._edgecolors2d = s3._edgecolor3d

ax.set(xlim=[0, 2000], ylim=([0, 2000]), zlim=([1000, 0]),
       xlabel=(r' $x [m]$'), ylabel=(r'$y [m]$'), zlabel=(r'$z [m]$'))

ax.legend()
ax.set_title('a short title', fontsize=18)

plt.show()
pgky5nke

pgky5nke1#

您可以缩小一点以使标签可见。例如:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(12, 4))
ax = fig.add_subplot(projection='3d')
x, y = np.meshgrid(np.arange(100)*20, np.arange(100)*20)
mask =  np.ones(x.shape)
s1 = ax.plot_surface(x, y, mask*400, linewidth=0, label='Reflector 1')
s1._facecolors2d = s1._facecolor3d
s1._edgecolors2d = s1._edgecolor3d
s2 = ax.plot_surface(x, y, mask*700, linewidth=0, label='Reflector 2')
s2._facecolors2d = s2._facecolor3d
s2._edgecolors2d = s2._edgecolor3d
s3 = ax.plot_surface(x, y, mask*1000, linewidth=0, label='Reflector 3')
s3._facecolors2d = s3._facecolor3d
s3._edgecolors2d = s3._edgecolor3d

ax.set(xlim=[0, 2000], ylim=([0, 2000]), zlim=([1000, 0]),
   xlabel=(r' $x [m]$'), ylabel=(r'$y [m]$'), zlabel=(r'$z [m]$'))

ax.legend()
ax.set_title('a short title', fontsize=18)
ax.set_box_aspect(aspect=None, zoom=0.8)
plt.show()

它创建了这个图:

相关问题