0

I have created 3D surface plots using matplotlib as described here. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such as Axes.set_xlim() (whether or not Axes.set_xbound()is used) limit the axis but not the data. The data is plotted and appears to continue beyond the axis limits.

The original plot before trying to set axis limits looks like this:

The original image: The original image

Here's what I get after I tried to limit the X (energy) axis:

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

Here's what I get after I tried to limit both the X and the Z axes:

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

I tried all the suggestions in this post and also this one. None worked.

I tried:

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

Also

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

and

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)

and

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

Here's the relevant code:

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)
M Z
  • 4,571
  • 2
  • 13
  • 27

0 Answers0