2
$\begingroup$

I know that you can use Map and pure functions to avoid retyping commands in Mathematica. In the case of ListPlot this works as follows

ListPlot[#, PlotRange -> All, Joined -> True, 
   ImageSize -> Large] & /@ {list1, list2}

With this I get a list of the two plots of list1and list2. What I want to know is whether there is a convenient way to use this construction but change the options e.g. of PlotLegends independently for the two plots? If I simply specify PlotLegends in the ListPlot command it will be the same for the two distinct plots of list1 and list2.

Thank you for your help.

$\endgroup$
4
  • $\begingroup$ Probably use MapThread. As an example MapThread[ ListLinePlot[#1, #2] &, {{list1, list2}, {{Frame -> True}, {PlotStyle -> Red, Axes->False}}}]. $\endgroup$
    – march
    May 14 '18 at 17:18
  • $\begingroup$ Yes, comes close to what I was looking for. Nevertheless, I was hoping for some kind of a mixture of both: To write those options which are shared among both plots only once, but still have full control over the options that are different for the two plots. I think that is not possible, right? MapThread[ ListLinePlot[#1, #2] &, {{list1, list2}, {{ImageSize -> Large, PlotRange -> All, PlotLabel -> {"test1"}}, {ImageSize -> Large, PlotRange -> All, PlotLabel -> {"test2"}}}}] Here I need to repeat PlotRange and ImageSize. $\endgroup$ May 14 '18 at 17:27
  • $\begingroup$ That's no problem! Just put the extra options before or after the #2: MapThread[ ListLinePlot[#1, #2, Frame -> True] &, {{list1, list2}, {{PlotStyle -> Blue}, {PlotStyle -> Red, BaseStyle -> {FontSize -> 20}}}}]. $\endgroup$
    – march
    May 14 '18 at 17:29
  • $\begingroup$ Sure, sometimes you don't see the wood for the trees. That's exactly what I was looking for. Thank you very much. Only a tiny problem, but always looking for the most efficient ways :) $\endgroup$ May 14 '18 at 17:32
6
$\begingroup$

One can use MapThread. As an example:

list1 = Range[10];
list2 = Range[10]^2;

Then, the options that they share can be put into the ListPlot call directly, and the options that they don't share are placed in the second list of the second MapThread argument:

MapThread[
  ListLinePlot[#1, #2, Frame -> True] &,
  {
    {list1, list2},
    {{PlotStyle -> Blue}, {PlotStyle -> Red, BaseStyle -> {FontSize -> 20}}}
  }
 ]

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.