# unmatched output for density plot

I am plotting Abs[R] on y-axis vs k on x-axis with the following code

ϖ = -2 Cos[κ];
α = 1;
Subscript[V, 0] = -2.5;
ε = 0.05;
μ = 0.3;
Subscript[V, 1] = Subscript[V, 0] (1 + ε);
Subscript[V, 2] = Subscript[V, 0] (1 - ε);
Subscript[δ, 2] =
Subscript[V, 2] - ϖ + (α*(Abs[R]))/(
1 + μ*(Abs[R]));
Subscript[δ, 1] =
Subscript[V,
1] - ϖ + (α*(Abs[R])*(1 -
2 Subscript[δ, 2]*Cos[κ] + Subscript[δ,
2]^2))/(1 + μ*(Abs[R])*(1 -
2 Subscript[δ, 2]*Cos[κ] + Subscript[δ,
2]^2)) ;
χ = -κ;
Subscript[ζ, 2] =
Subscript[V, 1] - ϖ + (α*(Abs[R]))/(
1 + μ*(Abs[R]));
Subscript[ζ, 1] =
Subscript[V,
2] - ϖ + (α*(Abs[R])*(1 -
2 Subscript[ζ, 2]*Cos[χ] + Subscript[ζ,
2]^2))/(1 + μ*(Abs[R])*(1 -
2 Subscript[ζ, 2]*Cos[χ] + Subscript[ζ, 2]^2))
;


Then the plot command

g1 = DensityPlot[{(Abs[(E^(I κ) -
E^(-I κ))/(1 + (Subscript[δ, 1] - E^(
I κ)) (E^(I κ) - Subscript[δ,
2]))]^2 -
Abs[(E^(I χ) -
E^(-I χ))/(1 + (Subscript[ζ, 1] - E^(
I χ)) (E^(I χ) - Subscript[ζ,
2]))]^2)/(Abs[(E^(I κ) -
E^(-I κ))/(1 + (Subscript[δ, 1] - E^(
I κ)) (E^(I κ) - Subscript[δ,
2]))]^2 +
Abs[(E^(I χ) -
E^(-I χ))/(1 + (Subscript[ζ, 1] - E^(
I χ)) (E^(I χ) - Subscript[ζ,
2]))]^2)} /. {Abs[R] -> x}, {κ, 0, π}, {x, 0,
10}, ColorFunction -> ColorData["SolarColors"], PlotPoints -> 200,
PlotRange -> All, AspectRatio -> 21/27, ImageSize -> 272,
Frame -> True, Axes -> True,
FrameLabel -> {κ, Style[Abs[R]^2, 21]},
FrameStyle -> Directive[Black, FontSize -> 18],
FrameTicks -> {{{0, 2, 4, 6, 8, 10}, None}, {{0, 1, 2, 3}, None}}]


I get an output which I believe is close to the desired one, but due to the wrong choice of colors (maybe) i can not match mine with the following which is the desired output, Can someone please help change the ColorFunction, so that I can get as close to the desired as possible. The required output with legend is • do you have image of the scale or legend ? – David Baghdasaryan Aug 13 '18 at 12:34
• @DavidBaghdasaryan, I updated the post with the legend. – AtoZ Aug 14 '18 at 2:56

This is how you can overcome this problem: You can get the pixel values corresponding to the function from legend picture like:

data = {{0, 0, 0}, {77, 0, 0}, {149, 0, 0}, {231, 0, 0}, {255, 60, 0}, {255, 135, 0}, {255, 222, 0}, {255, 255, 42}, {255, 255, 118}, {255, 254, 187}, {255, 255, 255}};,

than you can interpolate, rescaling the doman from {-1,1} to {0,1} (because it seems that ColorFunction clips the values to be positive) :

f = Interpolation[Transpose[{Range[0, 1, 0.1], 1/255. (data)}], x]; colorfunc[x_] = RGBColor[f];

g1 = DensityPlot[{(Abs[(E^(I κ) - E^(-I κ))/(1 + (Subscript[δ, 1] - E^( I κ)) (E^(I κ) - Subscript[δ, 2]))]^2 - Abs[(E^(I χ) - E^(-I χ))/(1 + (Subscript[ζ, 1] - E^( I χ)) (E^(I χ) - Subscript[ζ, 2]))]^2)/(Abs[(E^(I κ) - E^(-I κ))/(1 + (Subscript[δ, 1] - E^( I κ)) (E^(I κ) - Subscript[δ, 2]))]^2 + Abs[(E^(I χ) - E^(-I χ))/(1 + (Subscript[ζ, 1] - E^( I χ)) (E^(I χ) - Subscript[ζ, 2]))]^2)} /. {Abs[R] -> x}, {κ, 0, π}, {x, 0, 10}, PlotPoints -> 200, PlotRange -> All, AspectRatio -> 21/27, ImageSize -> 272, ColorFunction -> colorfunc, PlotLegends -> Automatic, Frame -> True, Axes -> True, FrameLabel -> {κ, Style[Abs[R]^2, 21]}, FrameStyle -> Directive[Black, FontSize -> 18], FrameTicks -> {{{0, 2, 4, 6, 8, 10}, None}, {{0, 1, 2, 3}, None}}]. • Sure, I just added two options ColorFunction -> colorfunc, PlotLegends -> Automatic – David Baghdasaryan Aug 15 '18 at 6:33