Reputation: 391
I am trying to make a 3d plot but the color range is so small that it only covers a small portion of the values that the z-axis can have. How do I fix this?
I attach the code and the image that I get:
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(B , ENERGY, result_plot, cmap=cm.Spectral_r , linewidth=0.0 ,antialiased =False)
colorbar( surf, shrink=0.5, aspect=3)
ax.view_init(30, 45)
plt.show()
Upvotes: 4
Views: 7515
Reputation: 1703
In the future please give a minimal and verifiable example. The color limits are determined based on your data. Therefore, I'm not entirely certain that your data supports more values than it shows. Using the example from the docs, we can use the vmin
and vmax
to force limits.
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False, vmin = -10, vmax = 10)
# Customize the z axis.
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
Upvotes: 8