5
$\begingroup$

I need to make a graph with multiple lines and points. Each line contains 3 points that should each be colored black, yellow, and red. The line should be a neutral gray.

I managed to create a graph that has those points without lines:

enter image description here

Graphics[
 Table[{Text[
    Style["•", Flatten[colors][[i]], Bold, 
     FontSize -> 20, FontFamily -> "Arial"],
    data[[i]]]}, {i, 1, Length[data]}], 
 ImageSize -> {500, 500}, Frame -> True]

And a graph that has those points connected by a line but colored incorrectly:

enter image description here

 ListLinePlot[Partition[data, 3], PlotMarkers -> {"•", 20}]

The data:

data = {{-0.962001,0.397816},{-0.122007,-0.0413612},{-0.0544419,-0.214962},{-0.135477,0.571107},{0.899526,0.190296},{0.898588,0.00546919},{-0.347618,0.666652},{0.246898,0.498308},{0.374387,0.483023},{-0.581681,0.14916},{-0.0997349,-0.10738},{0.0364981,-0.261247},{0.768949,0.875527},{1.95692,0.436888},{1.95962,0.355918},{-1.25323,0.307325},{-0.411717,-0.163014},{-0.387259,-0.196534},{-0.419625,0.287503},{-0.0076809,0.131083},{-0.0899933,0.17461},{0.0317604,-0.0695526},{0.370543,-0.260739},{0.513008,-0.325415},{0.424957,-0.103409},{0.94739,-0.363821},{1.24866,-0.520327},{-1.13206,0.149609},{-0.174019,-0.957962},{0.150149,-1.12718},{-1.10439,0.151338},{0.08283,-1.0489},{0.437483,-1.23367},{-1.13195,0.180468},{0.22697,-1.22584},{0.564093,-1.32619},{-1.12527,0.144753},{-0.31816,-0.769721},{0.13676,-1.08828},{0.512897,0.615075},{1.60425,0.266658},{1.56731,0.157649},{1.07963,0.691473},{2.32712,0.251782},{2.24102,0.203162},{0.146878,0.550012},{0.920199,0.229813},{0.93112,0.105877},{-0.618883,0.288482},{-0.114264,0.0952308},{-0.0902663,-0.0274716},{-0.42587,0.26112},{0.0296797,0.134414},{0.234351,0.0977336},{0.149234,0.312535},{0.566986,0.146658},{0.729692,0.192777},{-0.797245,0.301785},{-0.405653,0.129507},{-0.399827,0.125799},{-0.986633,0.301104},{-0.423614,-0.0630775},{-0.179002,-0.258728},{-1.06393,0.294462},{-0.646153,-0.0180542},{-0.530922,-0.174294},{-1.3346,0.288987},{-0.855399,-0.0954821},{-0.603291,-0.291644},{-0.953345,0.34497},{0.0734577,-0.507661},{0.495145,-0.806878},{-1.39286,0.27325},{-1.04882,-0.0124537},{-0.86758,-0.177823},{-1.07263,0.189348},{-0.87054,0.0332001},{-0.709255,-0.055134},{-0.884372,-0.133042},{-0.715605,-0.278561},{-0.450264,-0.591745},{0.00174907,0.689063},{0.857285,0.343011},{0.841798,0.233118},{0.268577,0.56418},{1.30903,0.0808955},{1.34309,-0.0496938},{-0.442908,0.205066},{0.156048,-0.103125},{0.229659,-0.2128},{-0.769446,0.115635},{-0.718515,0.0678925},{-0.687545,0.0584056},{-0.107299,0.0528954},{0.0258309,-0.0434246},{0.106836,-0.143284}}

colors = ConstantArray[{Black, Yellow, Red}, Length[repeatedStrainLabels]/3]

How can I get a graph that contains a gray line for every 3 elements in data, with the 1st element being a black point on the line, 2nd yellow, and 3rd red?

$\endgroup$

2 Answers 2

7
$\begingroup$
ListPlot[List /@ data, PlotStyle -> {Black, Yellow, Red}, 
 BaseStyle -> PointSize[Large], Epilog ->  {Gray, Line@Partition[data, 3]}]

enter image description here

Alternatively,

ListPlot[Riffle[List /@ data, Partition[data, 3]], 
 Joined -> {False, True}, 
 PlotStyle -> Riffle[{Black, Yellow, Red}, Gray, {2, -1, 2}], 
 BaseStyle -> PointSize[Large]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Interesting use of Epilog. Thanks! $\endgroup$
    – brienna
    Nov 26, 2018 at 0:56
3
$\begingroup$
Graphics[{Gray, Line@#, AbsolutePointSize[4], Black, Point[#[[1]]], 
    Yellow, Point[#[[2]]], Red, Point[#[[3]]]} & /@ 
  Partition[data, 3], Axes -> True]

enter image description here

$\endgroup$

Your Answer

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

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