This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Add-ons / Standard Packages / Graphics  /


MultipleListPlot augments the built-in function ListPlot by providing a convenient way to plot several lists on the same axes, each with a different style of plotting symbol. You can specify error bars with each data point, and a variety of styles for symbol styles exist, including various forms of labeled points.

Plotting several lists.

  • This loads the package.
  • In[1]:= <<Graphics`MultipleListPlot`

  • Here are some sets of data for use in the examples.
  • In[2]:= (list1 = Table[{x, Sin[2 Pi x]},
    {x, 0, 1, 0.1}];
    list2 = Table[{x, Cos[2 Pi x]},
    {x, 0, 1, 0.1}]);

  • This plots the lists on the same graph.
  • In[3]:= MultipleListPlot[list1, list2]

  • This connects the plotting symbols with lines of different styles.
  • In[4]:= MultipleListPlot[list1, list2,
    PlotJoined -> True]

  • The lines can be drawn for particular lists of data.
  • In[5]:= MultipleListPlot[list1, list2,
    PlotJoined -> {True, False}]

    Ways to specify a data point in a list of points for MultipleListPlot.

    There are several ways to specify the points in the data sets. The most basic involve only the locations of the points. If a point is given as a single number, the value is treated as a value, and the value is determined by the position of the point in the list of data. If given as a pair

    x,y, the point is placed at the

    x,y coordinates. Each point can be grouped with an error specification, given as an ErrorBar object. An ErrorBar object can accept a specification of error in the variable or in both and

    . An error given as a single value indicates the same error in the positive and negative directions; a negative number paired with a positive number indicates a different error in each direction.

  • This plots a single data set that has points with a variety of error specifications.
  • In[6]:= MultipleListPlot[
    {1.5, 3.2},
    {2.5, ErrorBar[0.3]},
    {{4.4, 5.2}, ErrorBar[{-0.5, 0.3}]},
    {{5.5, 2.1}, ErrorBar[{-0.4, 0.3}, {-0.2, 0.5}]} },
    PlotRange -> All,
    Frame -> True]

    Options for MultipleListPlot.

    A variety of characteristics of the plot can be modified by use of options. MultipleListPlot accepts all the usual Graphics and Legend options, as well as the options listed in the preceding table. Legend options are not employed unless PlotLegend is set to a list of labels for the data sets. Most of the options listed in the preceding table, except ErrorBarFunction, cyclically reuse the arguments if given in a list that is not as long as the number of data sets. The default symbol shapes and line styles provide for five data sets before cycling.
    The SymbolShape option may be set to a list of functions. Each function in the list should accept one argument specifying the location of a data point and should return graphics primitives representing the data point. The MultipleListPlot package includes some utilities to make generating these shapes easier, such as PlotSymbol, MakeSymbol, and RegularPolygon. SymbolShape can also take None, representing no drawn point (for instance, if only a line is desired), and Label, where the symbol is a label specified individually for each point by the SymbolLabel option.

  • This uses some options to MultipleListPlot.
  • In[7]:= MultipleListPlot[list1, list2,
    PlotStyle -> {GrayLevel[0], Dashing[{Dot, Dash}]},
    SymbolShape -> {PlotSymbol[Triangle], PlotSymbol[Box]},
    SymbolStyle -> {GrayLevel[0], GrayLevel[.5]}]

    MultipleListPlot can automatically generate a legend based on the styles for points and lines. The boxes in the legend are labeled by items from the PlotLegend option. All of the standard options to the Legend function (detailed in the chapter on the Graphics`Legend` package) can be used, including LegendPosition, LegendSize, LegendShadow, and others.

  • This is a MultipleListPlot with a key.
  • In[8]:= MultipleListPlot[list1, list2,
    PlotLegend -> {"Sine", "Cosine"},
    PlotJoined -> {False, True}

    Points can be labeled in a variety of ways. Labels can be placed by each point, or in place of the plotting symbol. Labels can be automatically generated, numbering the data set and the position in that data set. A user-specified function can also be used to automatically generate labels based on the position of the point in the data set.

  • Here is an example of labeling data points and using labels for symbols.
  • In[9]:= MultipleListPlot[list1, list2,
    SymbolShape ->
    {PlotSymbol[Star, Filled -> False], Label},
    SymbolLabel ->
    {Automatic, {"a", "b", "c", "d", "e"}},
    Frame -> True,
    PlotRange -> All

    The ErrorBarFunction option can be employed to draw the errors in a different fashion than the standard error bars. For instance, a common alternative is to draw error bars without serifs, or draw the area of the error in a rectangle or ellipse. The user function should take two arguments, where the first is the data point, and the second is an ErrorBar object. The point and error bar will always be completely specified, with the point as

    x,y and the error bar as ErrorBar[

    xerr,yerr], no matter what the input form of the data point.

  • This defines a sample function to use for drawing the errors.
  • In[10]:= mybarfunc[pt_, ErrorBar[xerr_, yerr_]] :=
    Disk[pt, {Max[Abs[xerr]], Max[Abs[yerr]]}]}

  • This plots the error bars as ellipses as defined by the given function.
  • In[11]:= MultipleListPlot[
    {{{1, 2}, ErrorBar[0.2, 0.4]},
    {{1.5, 3.2}, ErrorBar[0.4, 0.2]},
    {{3, 2.5}, ErrorBar[0.3, 0.1]},
    {{4.4, 5.2}, ErrorBar[.2, {-0.5, 0.3}]},
    {{5.5, 2.1}, ErrorBar[{-0.4, 0.3}, {-0.2, 0.5}]} },
    ErrorBarFunction -> mybarfunc]

    Specification of some standard plotting symbols.

    Some standard plot symbols are supplied for use with the SymbolShape option. These symbols can be drawn with a particular size and can also be drawn in outline. Completely arbitrary symbols can be constructed by applying MakeSymbol to a list of graphics primitives. The coordinates for the symbol are treated as offsets (in the Offset coordinate system) from the data point.

  • This is an example using some of the ways of creating additional plot symbols.
  • In[12]:= MultipleListPlot[
    Table[3.5, {7}],
    SymbolShape ->
    MakeSymbol[RegularPolygon[5, 3]],
    {Line[{{2, 2}, {-2, -2}}],
    Line[{{-2, 2}, {2, -2}}]}

    Generating regular polygon symbols.

    Additional plotting symbols can be created using the functions MakeSymbol and RegularPolygon. RegularPolygon generates a list of graphics primitives corresponding to shapes based on the regular polyhedra. MakeSymbol is applied to the primitives to create a plotting symbol. As an example, if you give a specification SymbolShape->

    MakeSymbol[RegularPolygon[m]],MakeSymbol[RegularPolygon[n]], your first list will be plotted using regular -sided polygons, the second list using regular -sided polygons, the third list using

    -sided polygons again, etc.

  • This displays a seven-pointed star.
  • In[13]:= Show[Graphics[
    RegularPolygon[7, 2, {0, 0}, 0, 3],
    AspectRatio -> Automatic]]

    Specifying dashing styles.

    The MultipleListPlot package enhances the Dashing and AbsoluteDashing styles to allow easy specification of dashing patterns in terms of dots, dashes, and long dashes.

  • This is a graphic demonstrating some possible dashing patterns.
  • In[14]:= Show[Graphics[MapIndexed[
    {#1, Line[{{0, -First[#2]}, {1, -First[#2]}}]}&,
    Dashing[{Dot, Dash}],
    Dashing[{Dot, Dash, Dot, LongDash}],
    Dashing[{Dot, Dot, Dash}]