# Changing ContourStyle based on an inequality

I would like to create a bifurcation diagram with ContourPlot. Suppose I want to plot the contour 1-2*a*Q+3*Q^3==0 with a the x-axis, Q the y-axis. I also want linestyle/thickness of the contour plot to change depending on the expression expr = 9*Q^2-2*a. If expr>0, I want it to be dashed; if expr<0, I want it to be a thick line. How to accomplish this?

Some previous posts about similar topic suggested putting an If statement inside the plot, but when I try something like

ContourPlot[If[expr>0, 1-2*a*Q+3*Q^3 == 0], {a,-2,2}, {Q,-2,2}]


it gives error.

You can create two contour plots, and show them together:

Show[
ContourPlot[
1-2*a*Q+3*Q^3==0, {a,-2,2}, {Q,-2,2},
RegionFunction->Function[{a,Q},9Q^2-2a<0],
ContourStyle->Thick
],
ContourPlot[
1-2*a*Q+3*Q^3==0, {a,-2,2}, {Q,-2,2},
RegionFunction->Function[{a,Q},9Q^2-2a>0],
ContourStyle->Dashed
]
]


Another possibility using a single contour plot:

ContourPlot[
{
ConditionalExpression[
1-2 a Q+3 Q^3,
9Q^2-2a<0
]==0,
ConditionalExpression[
1-2 a Q+3 Q^3,
9Q^2-2a>0
]==0
},
{a,-2,2},
{Q,-2,2},
ContourStyle->{Thick,Dashed}
]

• That solves my problem. But when I handle more complicated equations I want to define bifurEq=1-2*a*Q+3*Q^3. So in the RegionFunction I need to have something like Function[{a,Q},D[bifurEq,Q]>0], but then it gives me error saying that blah blah blah must be a Boolean function. How to fix this (have Mathematica do the algebra instead of me typing the equation myself)? Nov 17, 2019 at 18:09
• Try Function[{a, Q}, Evaluate @ D[bifurEq, Q] > 0] instead. Nov 17, 2019 at 18:11
• It works. Thank you. Nov 17, 2019 at 18:14