I have a nested matrix xyPairsAll
that contains {x, y} pairs:
{...
{{{1., 1812.}, {2., 10076.}, {3., 4764}},
{{1., 3475.}, {2., 3572.}, {3., 3985.}}},
{{{1., 6839.}, {2., 3849.}, {3., 2746}},
{{1., 3578.}, {2., 5629.}, {3., 3849.}}},
{{{1., 6839.}, {2., 3849.}, {3., 2746}},
{{1., 10092.}, {2., 1638.}, {3., 3728.}}}
...}
I need to plot xyPairsAll
with ListPlot. It would be easy if I could just flatten it to one level, but I need to keep the sublists distinct so that I can color the plot according to sublist.
The following statement only plots the first sublist:
ListPlot[#,
PlotRange -> {{0, 4}, Full},
Frame -> True,
FrameTicks -> {{Automatic, None}, {{1, 2, 3}, None}},
FrameLabel -> {"Time points", "Concentrations of CO2"},
ImageSize -> Full,
PlotLegends -> labels] & /@ xyPairsAll
How can I plot xyPairsAll
so that both conditions are met:
- each {x, y} pair gets its own dot
- all {x, y} pairs from each sublist share the same color
EDIT: In the original data matrix, I had a header plus xyPairsAll
. I set labels
to part of the header for the columns for the y-coordinates which each represent values of CO2 for a location (like {"Toronto, ON", "Boston, MA", "Washington, DC"...}
), and xyPairsAll
to all the corresponding rows after the header. So each sublist in xyPairsAll
represents {x, y} values for a location. If I flatten the xyPairsAll
, I don't think I can tell which {x, y} values are for which location. It'd just be one long list of {x, y} pairs.
ListPlot@Flatten[xyPairsAll, 1]
? $\endgroup$Flatten[xyPairsAll, 1]
@HenrikSchumacher $\endgroup$labels
? Flatten preserves the order, so usually you can use something like(ListPlot[#[[1]],PlotLegends->#[[2]]]&)/@Transpose[{Flatten[xyPairsAll,1],Flatten[sublistlabels,1]}]
. $\endgroup$