Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to create a plot where I have unconnected dots and some connected.

So far, I have figured out how to draw the dots.

My code is the following:

ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full]

I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots.

Do have any suggestions/hints on how to do that?

An example of what I want to do.

Thank you.

share|improve this question
    
Add this option at the end of ListPlot: Epilog -> {Line[ <list of points to join> ]}. – march 22 hours ago
    
...or you could use Prolog, if you want the line to go under the points. – J. M. 22 hours ago

3 Answers 3

up vote 5 down vote accepted

One possibility would be to use Epilog with Line:

ListPlot[
  {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, 
  Ticks -> {{1, 2, 3, 4}, None},
  AxesStyle -> Thin,
  TicksStyle -> Directive[Black, Bold, 12],
  Mesh -> Full,
  Epilog -> {
    Line[
      {{1, 1}, {2, 2}, {2, 5}, {3, 12}}
    ]
  }
]

ListPlot with Epilog connecting some of the points with a line.

A bit more concise:

pts = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}};

ListPlot[
  pts, 
  Ticks -> {{1, 2, 3, 4}, None},
  AxesStyle -> Thin,
  TicksStyle -> Directive[Black, Bold, 12],
  Mesh -> Full,
  Epilog -> {
    Line[
      pts[[{1, 2, 6, 15}]]
    ]
  }
]
share|improve this answer
ListPlot[{pts, pts[[{1, 2, 6, 15}]]}, Joined -> {False, True}, 
 Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, 
 TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full]

Mathematica graphics

share|improve this answer
 p1 =
    ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, 
          {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, 
          {3, 12}, {4, 13}, {2.5, 7}},
          Ticks -> {{1, 2, 3, 4}, None},
          AxesStyle -> Thin,
          TicksStyle -> Directive[Black, Bold, 12],
          Mesh -> Full];

p2 =
 ListLinePlot[{{1, 1}, {2, 2}, {3, 6}, {4, 10}}]

Show[p1, p2]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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