在 3D 图上设置轴限制的问题

问题描述 投票:0回答:0

我已经使用 matplotlib 创建了 3D 表面图,如 here 所述。一切正常,除非我设置轴限制。然后情节看起来很奇怪。似乎

Axes.set_xlim()
(无论是否使用
Axes.set_xbound()
)之类的命令限制了轴而不是数据。数据被绘制并且似乎继续超出轴限制。

尝试设置轴限制之前的原始图如下所示:

The original image

这是我尝试限制 X(能量)轴后得到的结果:

Surface plot after using Axes.set_xlim(left=0, right=10)

这是我尝试限制 X 轴和 Z 轴后得到的结果:

Surface plot after using using Axes.set_xlim(left=0, right=10) and axes[0].set_zlim(0, 3000)

我尝试了this postingthis one中的所有建议。没有工作。

我试过:

axes[0].set_xlim(left=0, right=10)
axes[0].set_zlim(0, 3000)

还有

axes[0].set_xlim(min=0, max=10)
axes[0].set_zlim(0, 3000)

axes[0].set_xlim(left=0, right=10)
axes[0].set_zlim(0, 3000)
axes[0].set_xbound(0, 10)
axes[0].set_zbound(0, 3000)

axes[0].set_xlim3d(left=0, right=10)
axes[0].set_zlim3d(0, 3000)

相关代码如下:

axes = []
fig0, ax0 = plt.subplots(subplot_kw={"projection": "3d"})
axes.append(ax0)

surf0 = axes[0].plot_surface(DS_ee, DS_cc, DS_array, cmap=cm.jet, linewidth=0, antialiased=False)

axes[0].xaxis.set_major_locator(MultipleLocator(10))
axes[0].xaxis.set_minor_locator(MultipleLocator(2))
axes[0].yaxis.set_major_locator(MultipleLocator(1))
axes[0].yaxis.set_minor_locator(MultipleLocator(0.2))

axes[0].set_zlabel('Default Spectrum [photons/keV/pixel]', fontsize=7)
axes[0].set_xlim(left=0, right=10)
axes[0].set_zlim(0, 3000)
# axes[0].set_xbound(0, 10)
# axes[0].set_zbound(0, 3000)

for t in axes[0].xaxis.get_major_ticks(): t.label.set_fontsize(6)
for t in axes[0].yaxis.get_major_ticks(): t.label.set_fontsize(6)
for t in axes[0].zaxis.get_major_ticks(): t.label.set_fontsize(6)

axes[0].grid(False)
axes[0].view_init(elev=elev_angle, azim=azim_angle)
axes[0].set(xlabel='E [keV]', ylabel=ylabel)
python matplotlib axis matplotlib-3d
© www.soinside.com 2019 - 2024. All rights reserved.