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...
Not sure how to fix this. Please help me.
Answer
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:
Comments
Post a Comment