4
$\begingroup$

Does anyone know how I can to draw a line connecting a list of data, while the dots are a colour and the line another colour?

As an example, the following is a list of data and how I plot them

list = {{1, 5}, {2, 8.5}, {3, 12}, {4, 17}, {5, 21.5}};
ListPlot[list, PlotStyle -> {Thick, Red}, PlotRange -> All]

What I want is not the following

ListLinePlot[list, PlotStyle -> {Thick, Red}, PlotRange -> All]

But rather, a way to have the points of the list in red colour and the line connecting them in black. (the colours are random of course).

Also, can someone tell me how to plot these points with a different style? For example instead of the dots, maybe a cross or a star or something.

Thanks in advance.

$\endgroup$
  • 2
    $\begingroup$ Try ListLinePlot[list, Mesh -> Full, MeshStyle -> Directive[AbsolutePointSize[6], Red], PlotStyle -> Directive[Thick, Black]]. If you want different markers, ListPlot[{{1, 5}, {2, 8.5}, {3, 12}, {4, 17}, {5, 21.5}}, Joined -> True, PlotMarkers -> Style["+", 16, Red], PlotStyle -> Directive[Thick, Black]] $\endgroup$ – J. M. is away Oct 1 '18 at 19:20
  • $\begingroup$ @J.M.issomewhatokay. Thank you. Excellent reply as always $\endgroup$ – Konstantinos Oct 1 '18 at 19:22
  • 1
    $\begingroup$ Also ListLinePlot[list, PlotStyle -> {Thick, Red}, PlotRange -> All, Epilog -> {Blue, AbsolutePointSize[8], Point[list]}] $\endgroup$ – Bob Hanlon Oct 1 '18 at 19:57
2
$\begingroup$
data = {{1, 5}, {2, 8.5}, {3, 12}, {4, 17}, {5, 21.5}};

I think you might reconsider ListLinePlot; it is perfectly capable of doing what you ask for.

ListLinePlot[data,
  PlotStyle -> {Thick, Black},
  PlotRange -> All,
  PlotMarkers -> {Style["\[FivePointedStar]", Red], 18}]

plot1

ListLinePlot[data,
  PlotStyle -> {Thick, Black},
  PlotRange -> All,
  Epilog -> {Text[Style["\[FivePointedStar]", Red, 20], #] & /@ data}]

plot2

$\endgroup$
  • $\begingroup$ Thanks a lot. Great suggestion $\endgroup$ – Konstantinos Oct 2 '18 at 7:45
3
$\begingroup$

You can also use PlotTheme with the setting "PlotMarkers","OpenMarkers" or "OpenMarkersThick":

ListLinePlot[{list, {0, 5} + # & /@ list}, PlotStyle -> {Red, Blue}, 
 PlotRange -> All, PlotTheme -> {"ThickLines", "OpenMarkersThick"}, 
 PlotLegends -> {"l1", "l2"}] 

enter image description here

Alternatively, use ListPlot and add the option `Joined -> True to get the same picture.

$\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.