5
Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},   ColorFunction -> (ColorData["VisibleSpectrum"][
     Rescale[#3, {0, 1}, {380, 750}]] &), PlotLegends -> Automatic]

enter image description here

There is no legend in this picture.

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
 ColorFunction -> (ColorData["VisibleSpectrum"][Rescale[#3, {0, 1}, {380, 750}]] &), 
 PlotLegends -> BarLegend[{"VisibleSpectrum", {0, 1}}]]

enter image description here

BarLegend["VisibleSpectrum"]

enter image description here

The color of lengend is wrong.

Mathematica 10.0.1. Is this a bug?

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
Apple
  • 3,663
  • 16
  • 25
  • I think the correct usage of the second argument should be BarLegend[{"VisibleSpectrum", {380, 750}}] but no, that doesn't work either... – C. E. Nov 24 '14 at 05:19
  • related: 38895. @Pickett almost :) see my answer. – Kuba Nov 24 '14 at 07:22
  • @Kuba wow, I only tried BarLegend on its own. You can't even set the scaling then as far I as I know. I count this as a bug.. – C. E. Nov 24 '14 at 12:09

1 Answers1

9
f@x_ := ColorData["VisibleSpectrum"][Rescale[x, {0, 1}, {380, 750}]]; 
Plot3D[
 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
 ColorFunction -> f, PlotLegends -> BarLegend[{f@# &, {0, 1}}]]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • I'm trying to perform your suggestion in a similar problem. However, here I'm using StreamDensityPlot instead of Plot3D. Therefore, my bar refers to the absolute value of the vector, i.e., ColorFunction -> (ColorData["VisibleSpectrum"][ Rescale[#5, {0, 1.2}, {380, 750}]] &). How could I adjust your code accordingly? – sined Nov 02 '20 at 20:15