0
$\begingroup$

I would like to combine two density plots using Show[ ] with different consecutive x-values so that the color scheme and legends match. For example,

plot01 = DensityPlot[2 Sin[x y], {x, 0, 1}, {y, 0, 3}, 
  ColorFunction -> "M10DefaultDensityGradient", 
  PlotLegends -> Automatic]

plot02 = DensityPlot[2 Sin[x y], {x, 1, 3}, {y, 0, 3}, 
  ColorFunction -> "M10DefaultDensityGradient", 
PlotLegends -> Automatic]

As such, plot01 has a scheme based on the range {0.0, 2.0} while plot02 has one based on the range {-2.0, 2.0}. I would like both of them to have a color scheme and legend based on {-2.0, 2.0} so that when they are combined, the colors match smoothly. How do I make this happen?

$\endgroup$
  • 2
    $\begingroup$ If you use single DensityPlot for full range {x, 0, 3} you will get what you want automatically. Why are you plotting the same function in different plots and then trying to stitch them? $\endgroup$ – Vitaliy Kaurov Oct 8 '18 at 8:37
1
$\begingroup$

If you have to use Show with two separate plots (rather than a single one with {x, 0, 3}), you can specify the range for color scheme as {-2,2} in both plots and add the option ColorFunctionScaling -> False:

plot01 = DensityPlot[2 Sin[x y], {x, 0, 1}, {y, 0, 3}, 
   ColorFunction -> ColorData[{"M10DefaultDensityGradient", {-2, 2}}], 
   ColorFunctionScaling -> False];
plot02 = DensityPlot[2 Sin[x y], {x, 1, 3}, {y, 0, 3}, 
   ColorFunction -> ColorData[ {"M10DefaultDensityGradient", {-2, 2}}], 
   ColorFunctionScaling -> False];
Legended[Show[plot01, plot02, PlotRange -> All], 
 BarLegend[{"M10DefaultDensityGradient", {-2, 2}}]]

enter image description here

| improve this answer | |
$\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.