3
$\begingroup$

I am ploting electronic band structure in Mathematica using ListLinePlot. Like this

enter image description here

However I don't want those vertical Lines indicated by red circle.

I want to delete those vertical lines and get this feel

enter image description here

An idea maybe to post-process the plot and keep styles intact. But I got lost in the complicated FullForm of Plot.

A simple example to start is for example ListLinePlot[{{1, 1}, {2, 1}, {2, 2}, {3, 2}}, Frame -> True]

$\endgroup$
10
  • $\begingroup$ ListLinePlot[ Split[{{1, 1}, {2, 1}, {2, 2}, {3, 2}}, First[#] != First[#2] &], Frame -> True]? $\endgroup$
    – kglr
    Commented Apr 11, 2017 at 11:52
  • $\begingroup$ Possible duplicate: mathematica.stackexchange.com/questions/11714/… -- The post-processing methods of some answers should work, and kglr's solution shows how to do it with ListLinePlot. $\endgroup$
    – Michael E2
    Commented Apr 11, 2017 at 11:53
  • $\begingroup$ Hi, @kglr. Thanks for your answer. The problem is that your method breaks one line into two line, and viewed as two colors. What if I want to visualize multiple lines $\endgroup$
    – matheorem
    Commented Apr 11, 2017 at 13:46
  • 1
    $\begingroup$ @matheorem, as you suggested post-processing is a way to keep the styles intact: ListLinePlot[{{1, 1}, {2, 1}, {2, 2}, {3, 2}}, Frame -> True] /. Line[x_] :> (Line /@ Split[x, First[#] != First[#2] &]) $\endgroup$
    – kglr
    Commented Apr 11, 2017 at 14:03
  • $\begingroup$ @kglr Works like a gem! Thank you so much! $\endgroup$
    – matheorem
    Commented Apr 11, 2017 at 14:39

1 Answer 1

4
$\begingroup$
ClearAll[postProcess]
postProcess = # /. Line -> Function[{x}, Line /@ Split[x, First[#] != First[#2] &]] &;

Example:

llp = ListLinePlot[{{{1, 1}, {2, 1}, {2, 4}, {4, 4}}, {{1, 2}, {3,  2}, {3, 3}, {4, 3}}}, 
   Frame -> True, PlotStyle -> {Directive[Red, Thick], Directive[Green, Thick]}, 
   ImageSize -> 250];


Row[{llp, postProces@llp}, Spacer[10]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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