Skip to main content
Tweeted twitter.com/StackMma/status/697972353477828608
added 4090 characters in body
Source Link
Espen Brun
  • 135
  • 1
  • 7

Edit

I was a bit unclear earlier, but I'll try to calrify now. I have made some more plots to illustrate what I mean. Sorry for the lengthy code.

myColRange[range_] := ColorData[{"StarryNightColors", range}];
cont = 15;

GraphicsGrid[{{

   ContourPlot[
    -Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
     ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    Contours -> cont,
    PlotLabel -> 
   "-\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
   \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    -Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {-3, 0}},
    PlotLabel -> 
     "-\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
     \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   ContourPlot[
    -3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    Contours -> cont,
    PlotLabel -> 
      "-3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    -3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {-3, 0}},
    PlotLabel -> 
      "-3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"]},

  {ContourPlot[
    Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False, Contours -> cont,
    PlotLabel -> 
     "\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \(2\)]\
     \) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {0, 3}},
    PlotLabel -> 
     "\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \(2\)]\
      \) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   ContourPlot[
    3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False, Contours -> cont,
    PlotLabel -> 
     "3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
       \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {0, 3}},
    PlotLabel -> 
     "3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"]}},

 ImageSize -> Large]

The code generates these plots

I am interested in the contourplots, but included the 3D plots to better illustrate what I want.

If you look at one row, the plots have the same range. In the first row the colors changes from -3 to 0, and in the second from 0 to 3. I want to keep it like that: plots in a row have the same scale on the colordata. The scale does not need to be the same for the two different rows, they just happen to be 0 and |3| here because I copy pasted.

What I want now is to reverse the colors of the positive plots in row 2, but I would like to keep the shape of the plot. So I want the peaks to be dark, and then grow lighter closer to 0.

I tried with the pure function proposed by JasonB, but then I get this

 myColPure[range_] := (ColorData[{"StarryNightColors", range}][1 - #] &)

enter image description here

Edit

I was a bit unclear earlier, but I'll try to calrify now. I have made some more plots to illustrate what I mean. Sorry for the lengthy code.

myColRange[range_] := ColorData[{"StarryNightColors", range}];
cont = 15;

GraphicsGrid[{{

   ContourPlot[
    -Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
     ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    Contours -> cont,
    PlotLabel -> 
   "-\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
   \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    -Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {-3, 0}},
    PlotLabel -> 
     "-\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
     \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   ContourPlot[
    -3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    Contours -> cont,
    PlotLabel -> 
      "-3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    -3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{-3, 0}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {-3, 0}},
    PlotLabel -> 
      "-3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"]},

  {ContourPlot[
    Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False, Contours -> cont,
    PlotLabel -> 
     "\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \(2\)]\
     \) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {0, 3}},
    PlotLabel -> 
     "\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \(2\)]\
      \) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   ContourPlot[
    3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False, Contours -> cont,
    PlotLabel -> 
     "3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
       \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"],

   Plot3D[
    3 Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
    ColorFunction -> myColRange[{0, 3}],
    ColorFunctionScaling -> False,
    PlotRange -> {{-2, 2}, {-2, 2}, {0, 3}},
    PlotLabel -> 
     "3\!\(\*SuperscriptBox[\(e\), \(\(-\*SuperscriptBox[\(x\), \
      \(2\)]\) - \*SuperscriptBox[\(y\), \(2\)]\)]\)"]}},

 ImageSize -> Large]

The code generates these plots

I am interested in the contourplots, but included the 3D plots to better illustrate what I want.

If you look at one row, the plots have the same range. In the first row the colors changes from -3 to 0, and in the second from 0 to 3. I want to keep it like that: plots in a row have the same scale on the colordata. The scale does not need to be the same for the two different rows, they just happen to be 0 and |3| here because I copy pasted.

What I want now is to reverse the colors of the positive plots in row 2, but I would like to keep the shape of the plot. So I want the peaks to be dark, and then grow lighter closer to 0.

I tried with the pure function proposed by JasonB, but then I get this

 myColPure[range_] := (ColorData[{"StarryNightColors", range}][1 - #] &)

enter image description here

added 15 characters in body
Source Link
Espen Brun
  • 135
  • 1
  • 7

The following two examples work

Plot3D[Exp[ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", {0, 1}}]]
Plot3D[Exp[ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}]]

I want to combine those two options, but the following does not work

Plot3D[Exp[ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", "Reverse", {1, 0}}]]  

The last plot is just black and I get the message

ColorData::notent: {TemperatureMap, Reverse, {1, 0}} is not a known entity,
class, or tag for ColorData. Use ColorData[] for a list of entities."

The above is just some minimum working example, and if you wonder why I want to do this, read the following: I am making several contourplots that I want to have the same color representing the same values, so I need to specify the values. I also have one set of plots that go from negative to 0, and one set that goes from 0 to some positive value. In the negative case the most negative value represents the largest effect, while in the positive case the most positive value represents the largest effect. I want largest effect in both cases to have the deepest color, so I need to invert one of the colorgradients.

Help is much appreciated.

enter image description here

The following two examples work

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", {0, 1}}]]
Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}]]

I want to combine those two options, but the following does not work

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", "Reverse", {1, 0}}]]  

The last plot is just black and I get the message

ColorData::notent: {TemperatureMap, Reverse, {1, 0}} is not a known entity,
class, or tag for ColorData. Use ColorData[] for a list of entities."

The above is just some minimum working example, and if you wonder why I want to do this, read the following: I am making several contourplots that I want to have the same color representing the same values, so I need to specify the values. I also have one set of plots that go from negative to 0, and one set that goes from 0 to some positive value. In the negative case the most negative value represents the largest effect, while in the positive case the most positive value represents the largest effect. I want largest effect in both cases to have the deepest color, so I need to invert one of the colorgradients.

Help is much appreciated.

enter image description here

The following two examples work

ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", {0, 1}}]]
ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}]]

I want to combine those two options, but the following does not work

ContourPlot[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", "Reverse", {1, 0}}]]  

The last plot is just black and I get the message

ColorData::notent: {TemperatureMap, Reverse, {1, 0}} is not a known entity,
class, or tag for ColorData. Use ColorData[] for a list of entities."

The above is just some minimum working example, and if you wonder why I want to do this, read the following: I am making several contourplots that I want to have the same color representing the same values, so I need to specify the values. I also have one set of plots that go from negative to 0, and one set that goes from 0 to some positive value. In the negative case the most negative value represents the largest effect, while in the positive case the most positive value represents the largest effect. I want largest effect in both cases to have the deepest color, so I need to invert one of the colorgradients.

Help is much appreciated.

enter image description here

Source Link
Espen Brun
  • 135
  • 1
  • 7

Specify range and reverse for colordata in contourplot

The following two examples work

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", {0, 1}}]]
Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2},
ColorFunction -> ColorData[{"TemperatureMap", "Reverse"}]]

I want to combine those two options, but the following does not work

Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> ColorData[{"TemperatureMap", "Reverse", {1, 0}}]]  

The last plot is just black and I get the message

ColorData::notent: {TemperatureMap, Reverse, {1, 0}} is not a known entity,
class, or tag for ColorData. Use ColorData[] for a list of entities."

The above is just some minimum working example, and if you wonder why I want to do this, read the following: I am making several contourplots that I want to have the same color representing the same values, so I need to specify the values. I also have one set of plots that go from negative to 0, and one set that goes from 0 to some positive value. In the negative case the most negative value represents the largest effect, while in the positive case the most positive value represents the largest effect. I want largest effect in both cases to have the deepest color, so I need to invert one of the colorgradients.

Help is much appreciated.

enter image description here