I want to set axis limits in matplotlib 3D plot to get rid of the value over 15,000.
I used 'set_zlim', but happened some error on my results.
how can I do?

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(10, 5))
ax = fig.gca( fc='w', projection='3d')
for hz, freq, z in zip(all_hz, all_freq,all_amp):
x = hz
y = freq
z = z
ax.plot3D(x, y, z)
ax.set_ylim(-10,15000)
ax.set_zlim(0,0.1)
plt.show()
This seem to be a flaw in the toolkit due to the perspective. The data is plotted without being cropped to the correct limits. You can always slice the data to the correct values:
import numpy as np
# define limits
ylim = (-10,15000)
zlim = (0,0.1)
x = hz
# slicing with logical indexing
y = freq[ np.logical_and(freq >= ylim[0],freq <= ylim[1] ) ]
# slicing with logical indexing
z = z[ np.logical_and(z >= zlim[0],z <= zlim[1] ) ]
ax.plot3D(x, y, z)
ax.set_ylim(ylim) # this shouldn't be necessary but the limits are usually enlarged per defailt
ax.set_zlim(zlim) # this shouldn't be necessary but the limits are usually enlarged per defailt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With