5
$\begingroup$
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?

$\endgroup$
3
  • $\begingroup$ I think the correct usage of the second argument should be BarLegend[{"VisibleSpectrum", {380, 750}}] but no, that doesn't work either... $\endgroup$ Commented Nov 24, 2014 at 5:19
  • $\begingroup$ related: 38895. @Pickett almost :) see my answer. $\endgroup$ Commented Nov 24, 2014 at 7:22
  • $\begingroup$ @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.. $\endgroup$ Commented Nov 24, 2014 at 12:09

1 Answer 1

9
$\begingroup$
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

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$ Commented Nov 2, 2020 at 20:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.