# How to plot parametric phase diagram with bar legend? [closed]

I am trying to plot the parametric phase diagram with bar legend in the form of a rainbow. I have asked one similar question before in which I have shown the region plot. But equations are different there. Here I have simplified the equations. I have written this code for getting the plot but not showing any color phase diagram as I want. If anyone can resolve this it will be appreciated.

k1 = 0.1;
kexc = .2;
ome = .4;
kL = (k1 + kexc)/2 - del0*(k1 - kexc)/(2*ome);
g0 = 0.3;
ome1 = 5.5;
a1 = 0.1;
A1 = 1;
B1 = 0;
gma = 0.0001;
delta = -1.5;
Y1 = (k1 - kexc)*g0^2*B1*ome1*(1 - del0/ome)*A1;
M1 = (gma^2/4 + ome1^2);
X1 = kL/2 + (k1 - kexc)/(ome^2*Sqrt[2]*M1)*g0^2*B1^2*ome1*P0*a1;
Z1 = delta + g0^2*(1 - del0/ome)*A1/Sqrt[2]*ome1/ome*P0*B1*a1/M1;
K1 = g0^2/2 (1 - del0/ome)^2*A1^2*ome1/M1;
S1 = g0^2/(2*Sqrt[2]*ome)*B1*ome1*(1 - del0/ome)*A1/M1;
O1 = (1 - del0/(2*ome))/Sqrt[2] + P0*g0^2*B1^2*ome1*a1/(2*ome^2*M1);
F11 = NSolve[
r1^3*(Y1^2 + K1^2) + r1^2*(2*X1*Y1 + 2*Z1*K1) +
r1*(X1^2 + Z1^2 + P0^2*S1 + 2*P0^2*O1*S1) + P0^2*O1 == 0, r1]
CounterPlot[{r1}, {P0, 0, 2.5}, {del0, 0, 3},
BarLegend["Rainbow", {0, 6}]]

• It's not really clear what you want to do in this code, but I can tell that you're using NSolve and ContourPlot incorrectly. (1) NSolve generates a list of rules that need to be applied to r1; replace r1 with r1 /. F11 if you want to plot the solutions to the functions found by NSolve. (2) The syntax for a legend is PlotLegends->(something). (3) You misspelled ContourPlot. Commented May 21, 2020 at 16:40

1. It's ContourPlot, not CounterPlot.
2. If you fix that, your code will then complain about BarLegend.
3. If you remove BarLegend, it will return nothing, because r1 does not have a value. You have not substituted the solutions of your equation in it...

You also receive three solutions to your equation. I do not know the physical significance, but you may have to choose the right one or treat them one at a time. That's up to you. I do not know your model of physical problem.

First, rationalize numbers rather than use machine-precisions:

k1 = 1/10;
kexc = 2/10;
ome = 4/10;
kL = (k1 + kexc)/2 - del0*(k1 - kexc)/(2*ome);
g0 = 3/10;
ome1 = 55/10;
a1 = 1/10;
A1 = 1;
B1 = 0;
gma = 1/10000;
delta = -3/2;


Use the rest of your definitions as is, except for F11, where I will use Solve instead of NSolve, and ask specifically for Real solutions only, so Solve will generate ConditionalExpression results that include appropriate conditions on the parameters that make the expressions reals (your original code could generate imaginary results):

F11 =
Solve[
r1^3*(Y1^2 + K1^2) + r1^2*(2*X1*Y1 + 2*Z1*K1) + r1*(X1^2 + Z1^2
+ P0^2*S1 + 2*P0^2*O1*S1) + P0^2*O1 == 0,
r1,
Reals
];


Let's take a look at what we have, for each one of the three solutions:

ContourPlot[#, {P0, 0, 2}, {del0, 0, 3}, PlotRange -> All] & /@ (r1 /. F11)


It will be up to you to see which has significance to you. If you want to combine multiple plots, consider using Show.

• Sir, where should I use 'Show' to combine all these three plots?
– vini
Commented May 21, 2020 at 16:55
• Have you tried Show[ContourPlot[...]& /@ (r1 /. F11)] as a start? You may also try to combine the three in a single ContourPlot[Evaluate[r1 /. F11], ...]. Commented May 21, 2020 at 18:07