I am making a Table of ListPlots, in which I superimpose two ListPlots with Show.

I would like to make each nth element of a different colour and with a diffenret label on the legend.

The line in the code is this:

plots =  Table[
   ListPlot[cumulativeMaximaOut[[n]][[2]]]], {n, 1, Length[xm]}]

Is it possible to make each nth element automatically of a different colour (and label), or do I have to define a string of labels and of colours before hand (of finite length then)?

I tried this:

plots =  Table[
  ListPlot[{Labeled[cumulativeMaximaOut[[n]][[1]], "sqrt"], 
    Labeled[cumulativeMaximaOut[[n]][[2]], "log"]}], {n, 1, 

and it says:

Requested order is too high; order has been reduced to {2}


Data for cumulativeMaximaOut is here: http://pastebin.com/cb9i9FeP,

xm = {2,3,4}

  • $\begingroup$ This may have something to do with the internal structure of your data. You need to provide some representative data for your cumulative... list, and xm. $\endgroup$ – MarcoB Nov 24 '16 at 19:17
  • $\begingroup$ Do I just write down what values the arrays have? Is there a better way of providing data here? $\endgroup$ – SuperCiocia Nov 24 '16 at 19:21
  • $\begingroup$ You can use e.g. pastebin to share larger amounts of data: paste the data there and then add a link to your original question. $\endgroup$ – MarcoB Nov 24 '16 at 19:22

I created some synthetic data that is the value of Sin from 0 to with a variable frequency.

data = Table[{θ, Sin[n θ]}, {n, 1, 6}, {θ, 0, 2 π, 2 π/500}];

ListPlot itself can handle the this with multiple colors.


Mathematica graphics

You need to do something to handle the legends

 PlotStyle -> PointSize[0.01],
 PlotLegends -> Flatten@Table[
    {"Sin[" ~~ ToString[n] ~~ " x]", 
     "Sin[" ~~ ToString[n + 1] ~~ " x]"},
    {n, 1, Length[data] - 1, 2}

Mathematica graphics

There are many approaches you can use to create the legends depending upon the character of your data.

| improve this answer | |

I am not entirely sure that I understand your final desired formatting. However, here is an attempt at differentiating the two data series present in each component of your data set:

   PlotStyle -> {PointSize[0.03], PointSize[0.005]},
   PlotLegends -> {"sqrt", "log"},
   PlotRange -> {{-300, 6800}, {-3, 49}},
   Axes -> False, Frame -> True,
   ImageSize -> Medium
] & /@ cumulativeMaximaOut

Mathematica graphics

| improve this answer | |
  • $\begingroup$ Oh yeah sorry I guess I was wrong in the code. I actually meant to plot all the three graphs on top of each other, each with a different colour and label. Do you have any idea on how to do that? $\endgroup$ – SuperCiocia Nov 24 '16 at 22:10

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.