2
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

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]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you! Does this work with ListLogPlot? $\endgroup$ – John Taylor Feb 11 at 18:28
  • $\begingroup$ @JohnTaylor, it does if you add the option Joined->True. Try ListLogPlot[data, Joined -> True, Mesh -> {{x0}}, MeshShading -> {Dashed, Dashing[{}]}, PlotStyle -> Thick, MeshStyle -> Opacity[0]] $\endgroup$ – kglr Feb 11 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 at 19:27
  • 1
    $\begingroup$ @JohnTaylor, you can plot the two datasets separately and combine them using Show. $\endgroup$ – kglr Feb 11 at 19:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.