2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Add this option at the end of ListPlot: Epilog -> {Line[ <list of points to join> ]}. $\endgroup$ – march Nov 3 '15 at 18:50
  • $\begingroup$ ...or you could use Prolog, if you want the line to go under the points. $\endgroup$ – J. M. will be back soon Nov 3 '15 at 19:01
5
$\begingroup$

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}]]
    ]
  }
]
$\endgroup$
7
$\begingroup$
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

$\endgroup$
3
$\begingroup$
 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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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