Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I tried

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
 ColorFunction -> (ColorData["TemperatureMap"][#3] &),
 PlotLegends -> Automatic]

in an attempt to add a colorbar legend to the plot, but this did not work. It did work here:

DensityPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
 ColorFunction -> "SunsetColors",
 PlotLegends -> Automatic]

Any suggestions in how I can get it to work in the first bit of code?

Thanks.

share|improve this question
1  
Try specifying it manually, e.g. PlotLegends -> BarLegend["TemperatureMap"]. You'd need additional customizations in most cases to make sure the legend matches the plot. –  Szabolcs Mar 15 '13 at 19:00
add comment

1 Answer

A little twisted, and needs some generalisation:

<< PlotLegends`;
c = ColorData["TemperatureMap"];
s := Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},  ColorFunction -> (c[#3] &), 
            ImageSize -> {300, 300}];
k = ShowLegend[ s /. Plot -> DensityPlot, {c[1 - #1] &, 10, " 1", " 0",  
              LegendPosition -> {1.1, -.4}, LegendShadow -> None}] /.  
              Graphics[{_, b_}, ___] :> Graphics[b, ImageSize -> 50];
GraphicsGrid[{{s, k}}]

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.