Reputation: 115
I'm doing a 3D plot where the Z values stretch from 0 to approximately 1. I wonder if it's possible to have a colormap where my 0.999 values are differentiable from my 0.99 values so I can discern those peaks.
Here's my current relevant code:
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X_grid, Y_grid, Z_grid, cmap=cm.coolwarm)
edit for clarity:
I have continuous Z-values from 0 to 1. Most of my values are around 0.990 though with a few peaks around 0.999. So a continuous colormap that has "higher resolution" and goes from one color from 0.990 to another color at 0.999 so that that last +0.009 change is visible is what I'm looking for. A binary solution where all the values above a given number (e.g. 0.998) would be alright as well although maybe not as good looking!
Upvotes: 1
Views: 318
Reputation: 14997
You can set 3 special colors for matplotlib color maps, over, under and bad. These are the colors for values outside the range and nan values respectively.
For your use case, you could set the max value of the color range to 0.99 and set the over color like this:
cmap = plt.get_cmap('coolwarm')
cmap.set_over('black')
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X_grid, Y_grid, Z_grid, cmap=cmap, vmax=0.99)
Upvotes: 2