Consider a set of data {{x,y}}. How to plot it in the way such that for all x > x0 the plot line will be solid, while for x < x0 it will be dashed?
$\begingroup$
$\endgroup$
You can use Mesh
and MeshShading
:
SeedRandom[1]
data = SortBy[RandomReal[10, {50, 2}], First];
x0 = 3;
ListLinePlot[data,
Mesh -> {{x0}},
MeshShading -> {Dashed, Dashing[{}]},
PlotStyle -> Thick,
MeshStyle -> Opacity[0]]
-
$\begingroup$ Thank you! Does this work with ListLogPlot? $\endgroup$ – John Taylor Feb 11 '19 at 18:28
-
$\begingroup$ @JohnTaylor, it does if you add the option
Joined->True
. TryListLogPlot[data, Joined -> True, Mesh -> {{x0}}, MeshShading -> {Dashed, Dashing[{}]}, PlotStyle -> Thick, MeshStyle -> Opacity[0]]
$\endgroup$ – kglr Feb 11 '19 at 18:33 -
$\begingroup$ Thank you again! Sorry again, but could you please tell how to plot two datasets data1, data2 and apply the meshing only to one of them? $\endgroup$ – John Taylor Feb 11 '19 at 19:27
-
1$\begingroup$ @JohnTaylor, you can plot the two datasets separately and combine them using
Show
. $\endgroup$ – kglr Feb 11 '19 at 19:41