# changing line style from solid to dashed after an intersection

I used this link: Plot that draws a dashed/solid curve depending on the y-value of the curve to help me start this. I have two lines. I want to change from solid to dashed after an intersection. The line with higher slope will have dashed line AFTER the intersection and the line with lower slope will have dashed line BEFORE the intersection. These two lines should be red and blue.

Here is what I have done so far...

In[289]:= y1 = 1.44; y2 = 27.9 - 16000 x;
intercept = x /. Solve[y1 == y2, x][[1]]

Out[290]= 0.00165375


The plot...

Plot[{y1, y2}, {x, .0014, .0019}, PlotRange -> All,
MeshFunctions -> {#1 &},
Mesh -> {{0.0014, intercept}, {intercept, 0.0019}},
MeshShading -> {Blue, Directive[Blue, Dashed]}, MeshStyle -> None]


Here was the result...

If you're not wed to Mesh, it might be easier for you to accomplish what you're looking for with just having multiple functions, ala:

Plot[{ If[intercept > x, y1, None], If[intercept < x, y1, None],
If[intercept > x, y2, None], If[intercept < x, y2, None]} //
Evaluate, {x, .0014, .0019}, PlotRange -> All,
PlotStyle -> {{Blue, Dashed}, {Blue}, {Red}, {Red, Dashed}},
Axes -> False, Frame -> True,
Epilog -> {PointSize[1/40], Gray, Point[{intercept, y1}]}]


yielding

(if you hate the dot get rid of the epilog)

Update riffing off your previous question re: Callouts, can combine as, e.g.

{f1, f2, f3, f4} = { If[intercept > x, y1, None],
If[intercept < x, y1, None],
If[intercept > x, y2, None], If[intercept < x, y2, None]};

xRange = {.0014, .0019}; yRange = {-3, 8};

Plot[ {Callout[f1, "labelY1", {0.001775, 3.64}, {0.00174, 1.754}],
f2, f3,
Callout[f4, "labelY2", {0.001525, 5.7}, {0.00156, 3.3142}]} //
Evaluate, Prepend[x][xRange],
PlotStyle -> {{Blue, Dashed}, {Blue}, {Red}, {Red, Dashed}},
PlotRange -> yRange, Axes -> False, Frame -> True]


yielding:

• So here, LabelY1 and LabelY2 cannot have assigned values with units. Which, would go back to my original problem in that question Commented Sep 13, 2017 at 23:18
• I just used the strings "LabelY1" and "LabelY2" to not overly import from the other question. Can completely use e.g.: Plot[ {Callout[f1, formatQ["operational", q1], {0.001775, 3.64}, {0.00174,1.754}], f2, f3, Callout[f4, formatQ["accelerated", q2], {0.001525, 5.7}, {0.00156, 3.3142}]} // Evaluate, Prepend[x][xRange], PlotStyle -> {{Blue, Dashed}, {Blue}, {Red}, {Red, Dashed}}, PlotRange -> yRange, Axes -> False, Frame -> True] where formatQ provides formatting based upon data in q1 and q2. Commented Sep 13, 2017 at 23:22
• ok, I see what you mean now. That works very well. Commented Sep 13, 2017 at 23:25
Show[
Plot[y1, {x, .0014, .0019},
Mesh -> {{0.0014, intercept}, {intercept, 0.0019}},

Plot[y2, {x, .0014, .0019},
Mesh -> {{0.0014, intercept}, {intercept, 0.0019}},

PlotRange -> All]


• Ok, will try that. My actual plot has multiple things going on. I will see if this way interferes with the functions I would like to see on the plot. Commented Sep 13, 2017 at 22:39

You have over specified your Mesh option. You only need: Mesh -> {{intercept}}. Unfortunately this solution does use show.

Show[
Plot[#1, {x, .0014, .0019},
PlotRange -> All,
Mesh -> {{intercept}},

• I want the results to look like @eldo answer, but I do not want to use Show Commented Sep 13, 2017 at 22:52