2
$\begingroup$

Simple example:

Normally: ListPlot[list, Joined->True]

If I want to map ListPlot how do I keep the Joined option?

thanks.

$\endgroup$
5
  • 2
    $\begingroup$ Why don't you simply do ListPlot[#, Joined -> True] & /@ {list1, list2}? $\endgroup$
    – Öskå
    May 15, 2014 at 18:36
  • 2
    $\begingroup$ Thanks, I am new at Mathematica. I apologize. $\endgroup$ May 15, 2014 at 18:42
  • 3
    $\begingroup$ @Öskå It is indeed very basic, but maybe we should keep it. Other beginners could likely search for the very same problem. The title is descriptive. You could post an answer. $\endgroup$
    – Szabolcs
    May 15, 2014 at 19:00
  • 2
    $\begingroup$ ListPlot with option Joined -> True is probably not the best example here, since ListLinePlot would seem to render the option superfluous. $\endgroup$
    – murray
    May 15, 2014 at 19:36
  • 1
    $\begingroup$ Somewhat related: (6955) and (29503) $\endgroup$
    – Mr.Wizard
    May 15, 2014 at 22:35

1 Answer 1

6
$\begingroup$

If you consider the following lists:

SeedRandom@1; list1 = RandomReal[{0, 10}, {10, 2}];
SeedRandom@2; list2 = RandomReal[{0, 10}, {10, 2}];

One can easily Map ListPlot by doing:

Map[ListPlot, {list1, list2}]
(* eq. to: ListPlot /@ {list1, list2} *)

Mathematica graphics

If you want to use Options with the ListPlot you need to define a function with the options in place. You can use either a conventional pattern-based function:

lp[x_] := ListPlot[x, Joined -> True, PlotMarkers -> Automatic]

or you could use a pure function:

lp = ListPlot[#, Joined -> True, PlotMarkers -> Automatic]&

Then you can use it as follows:

Map[lp, {list1, list2}]
(* eq. to: lp /@ {list1, list2} *)

Mathematica graphics

Of course, it can still be used without Map:

lp[{list1, list2}]

Mathematica graphics

$\endgroup$
2
  • 1
    $\begingroup$ I edited this answer slightly as I felt it was misleading to say that you need to use a pure function. $\endgroup$ May 15, 2014 at 20:41
  • 1
    $\begingroup$ That's right thanks :) $\endgroup$
    – Öskå
    May 15, 2014 at 20:52

Your Answer

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

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