0

I have a 4D plot with this:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm

x = np.arange(100)/ 101
y = np.sin(x) + np.cos(x)
X,Y = np.meshgrid(x,y)
Z = (X**2) / (Y**2)
A = np.sin(Z)

fig = plt.figure()
ax = fig.add_subplot(111,projection= '3d' )
ax.plot_surface(X,Y, Z, facecolors=cm.Oranges(A))
plt.show()

Output Image

But how do I view the scale of the colormap?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

You need to create a mappable from the colormap

m = cm.ScalarMappable(cmap=cm.Oranges)
m.set_array(A)
cbar = plt.colorbar(m)

as in the answer to this question: Matplotlib 3d plot - associate colorbar with different axis

Community
  • 1
  • 1
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Why are you reposting someone else's answer? you have already voted to close this as a dup so is this just for rep? – Tadhg McDonald-Jensen Feb 21 '17 at 23:21
  • In general terms it is of course a duplicate. But you never know on which level the question is asked and whether the questioner directly sees the overlap to the question and its answer. So it makes sense (at least to me) to provide a tailored answer to this question, which can be copied/pasted to make the above code work. Also for others coming to this question through search this answer might be more helpful, because it is more condensed to answer how to obtain a colorbar (while the other question also has some components about rotating X and Z in it). – ImportanceOfBeingErnest Feb 22 '17 at 08:11
  • well you have clearly put a lot more thought into this then I have, sorry about the accusation and you are right this is a much more strait forward answer then the other one. – Tadhg McDonald-Jensen Feb 23 '17 at 18:51