2
$\begingroup$

I am trying to make a contour plot of a gravitational potential, consisting of a sum og different potential.s.

I would like to plot them separately with a BarLegend that has the same colors for the same values of the potential. What I got now is that the colors in the two plots does not represent the same potential energy. Here's an example:

contplotb = 
  ContourPlot[1/Sqrt[R^2 + z^2 + 1], {R, 0, 10}, {z, -10, 10}, 
  PlotRange -> All,
  PlotLegends -> BarLegend[Automatic, All, LegendFunction -> "Panel"]]

 contplotd = 
  ContourPlot[3/Sqrt[R^2 + z^2 + 1], {R, 0, 10}, {z, -10, 10}, 
   PlotRange -> All,
   PlotLegends -> BarLegend[Automatic, All, LegendFunction -> "Panel"]]

As you may see, the colors represent different values, but it would be nice to have them represent the same

Any tips are much apreciated, and please include code if you have a solution, I'm very new to Mathematica.

Thanks Espen

$\endgroup$
  • $\begingroup$ closely related Q/As: Scale coloring of ContourPlot and Set the same color scale across multiple ListContourPlots $\endgroup$ – kglr Apr 13 '15 at 19:03
  • 1
    $\begingroup$ Use ColorFunction -> ColorData[{"Rainbow", {0, 3}}], ColorFunctionScaling -> False on both plots $\endgroup$ – Dr. belisarius Apr 13 '15 at 19:44
  • $\begingroup$ Thank you, guys! I checked out those other posts, but they seemed a bit more advanced than what I was after. Belisarius' answer worked just as I was hoping for. $\endgroup$ – Espen Brun Apr 14 '15 at 6:46
  • $\begingroup$ @belisarius Answer, or Close? $\endgroup$ – Mr.Wizard May 23 '15 at 13:41
3
$\begingroup$

Since Belisarius answered this in comments, this is just so people know that it has been dealt with.

Use

ColorFunction -> ColorData[{"Rainbow", {0, 3}}], ColorFunctionScaling -> False

for each plot.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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