2

How I can use Hue as color function in BarLegend in this density plot?

ShowLegend[
 DensityPlot[1 - Abs[Sin[x] Sin[y]], {x, -2, 2}, {y, 0, 3}, 
  PlotRange -> All, ImageSize -> 280, AspectRatio -> 1, 
  LabelStyle -> {FontSize -> 17, Black, Bold}, Frame -> True, 
  ColorFunction -> (Hue[1 - (0.7 # + 0.31)] &), 
  ColorFunctionScaling -> False, 
  PlotPoints -> 50], {ColorData[(Hue[1 - (0.7 # + 0.31)] &)] &, 10, 
  " 1", " 0", LegendPosition -> {1, 0.15}, 
  BaseStyle -> {FontSize -> 16, Bold, Black}, LegendShadow -> None}]

enter image description here

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
MMA13
  • 4,664
  • 3
  • 15
  • 21

2 Answers2

1

For example

DensityPlot[
 1 - Abs[Sin[x] Sin[y]], {x, -2, 2}, {y, 0, 3},
 ImageSize -> 280,
 ColorFunction -> (Hue[1 - (0.7 # + 0.31)] &),
 PlotLegends -> Placed[Automatic, Below],
 PlotPoints -> 50]

enter image description here

DensityPlot[
 1 - Abs[Sin[x] Sin[y]], {x, -2, 2}, {y, 0, 3},
 ImageSize -> 280,
 ColorFunction -> "Rainbow",
 PlotLegends -> 
  Placed[BarLegend[{"Rainbow", {0, 1}}, 
    LegendMarkerSize -> 200], {{1, 0}, {1, 1}}],
 PlotPoints -> 50]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
  • using plotlegend is not helping to make the plot consistant with the barlegend, showlegend provide many options. I would like to know if there is a way to use a desired color with ColorData apart from "Rinbow", "TemperatureMap", SunsetColors, and ...etc – MMA13 Dec 07 '15 at 02:02
1

I agree with others that you can have all the functionality without using the old PlotLegends package, I'd be interested in knowing if there are any options you want to add but cannot. That being said, you can get Hue to work with ShowLegend easily enough. You just had the color function formatted improperly. There's no reason to wrap Hue with ColorDataFunction

ShowLegend[
 DensityPlot[1 - Abs[Sin[x] Sin[y]], {x, -2, 2}, {y, 0, 3}, 
  PlotRange -> All, ImageSize -> 280, AspectRatio -> 1, 
  LabelStyle -> {FontSize -> 17, Black, Bold}, Frame -> True, 
  ColorFunction -> (Hue[1 - (0.7 # + 0.31)] &), 
  ColorFunctionScaling -> False, 
  PlotPoints -> 50], {(Hue[1 - (0.7 # + 0.31)] &), 10, " 1", " 0", 
  LegendPosition -> {1, 0.15}, 
  BaseStyle -> {FontSize -> 16, Bold, Black}, LegendShadow -> None}]

enter image description here

By the way, it looks like you are trying to recreate the MATLAB Jet color scheme by restricting the Hue values to between 0 and 0.7. You can also use a Jet-like color scheme directly, which I've defined in this pastebin:

<< "http://pastebin.com/raw.php?i=Dgck3tBL";
ShowLegend[
 DensityPlot[1 - Abs[Sin[x] Sin[y]], {x, -2, 2}, {y, 0, 3}, 
  PlotRange -> All, ImageSize -> 280, AspectRatio -> 1, 
  LabelStyle -> {FontSize -> 17, Black, Bold}, Frame -> True, 
  ColorFunction -> JetCM, ColorFunctionScaling -> False, 
  PlotPoints -> 50], {JetCM, 10, " 1", " 0", 
  LegendPosition -> {1, 0.15}, 
  BaseStyle -> {FontSize -> 16, Bold, Black}, LegendShadow -> None}]

enter image description here

Jason B.
  • 68,381
  • 3
  • 139
  • 286