MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: DisplayTogether & PlotLegend incompatibility

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70838] RE: [mg70815] DisplayTogether & PlotLegend incompatibility
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 28 Oct 2006 23:38:45 -0400 (EDT)

Hello Will,

Well, I wouldn't use MultipleListPlot. And then I wouldn't use Legend. And
then I wouldn't use DisplayTogether. Instead I will give another shameless
promotion for the DrawGraphics paradigm.

Needs["DrawGraphics`DrawingMaster`"]

data = {{{1, 0}, {2, 1}, {3, 2}},
    {{1, 1}, {2, 2}, {3, 3}},
    {{1, 2}, {2, 3}, {3, 4}}};

ptdata = {{1.5, 2.5}, {2, 2}, {2.5, 1.5}};

style1 = AbsoluteDashing[{}];
style2 = AbsoluteDashing[{5, 5}];
style3 = AbsoluteDashing[{2, 5, 10, 5}];

A legend is usually not a great idea. It does have a few uses but generally
it is just an indirect way to label curves or parts of a diagram.
Furthermore, the Legend often dominates the graphic and only distracts from
the real data. It is generally much better if you can label the curves
directly. The following plot uses direct labeling of the curves.

Draw2D[
    {style1, Line[Part[data, 1]],
      style2, Line[Part[data, 2]],
      style3, Line[Part[data, 3]],
      AbsolutePointSize[5], Point /@ ptdata,
      Text["one", {2.28211, 1.15819}, {-1, 0}],
      Text["two", {2.22898, 2.07511}, {-1, 0}],
      Text["three", {2.14043, 2.99204}, {-1, 0}]},
    Frame -> True,
    FrameLabel -> {"Displacement, mm", "Force, N"},
    PlotLabel -> "Direct Curve Labeling",
    ImageSize -> 400];

But if you do want a legend, then it is easier to draw it yourself directly
on the plot, especially since it is somewhat difficult to control Legend.
The following uses a legend.

Draw2D[
    {style1, Line[Part[data, 1]],
      style2, Line[Part[data, 2]],
      style3, Line[Part[data, 3]],
      AbsolutePointSize[5], Point /@ ptdata,
      style1, Text["one", Scaled[{0.05, 0.9}], {-1, 0}],
      Line[{Scaled[{0.2, 0.9}], Scaled[{0.3, 0.9}]}],
      style2, Text["two", Scaled[{0.05, 0.85}], {-1, 0}],
      Line[{Scaled[{0.2, 0.85}], Scaled[{0.3, 0.85}]}],
      style3, Text["three", Scaled[{0.05, 0.8}], {-1, 0}],
      Line[{Scaled[{0.2, 0.8}], Scaled[{0.3, 0.8}]}]},
    Frame -> True,
    FrameLabel -> {"Displacement, mm", "Force, N"},
    PlotLabel -> "Labeling With a Legend",
    ImageSize -> 400];

This involves a little more detail work than using MultiListPlot and Legend,
but you have absolute control and no suprises. You can just draw all the
elements you want, one after the other, in a single plot statement.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Will Robertson [mailto:wspr81 at gmail.com]
To: mathgroup at smc.vnet.net


Hello,

Having been used to plotting graphs in another system, I find myself out of
my
depth in Mathematica :)

In the attached code, I use the MultipleListPlot & Legend packages to
try and plot a set of curves with some overlayed points using
DisplayTogether. This works well until I try and add a legend (with
PlotLegend) as you can see. The second set of data is scaled way out of
proportion. Is this a misconception on my part?

(I don't really want to do everything in a single MultipleListPlot
because I algorithmically assign colours to the first set of graphs
with something like
  manyHues[steps_] := Table[{Hue[i/steps, 1, 0.8]}, {i, 1, steps, 1}]
Maybe there's a better way to do this...)

Any help would be greatly appreciated.
Many thanks!

Will Robertson
Adelaide, Australia


<<Graphics`MultipleListPlot`
<<Graphics`Legend`

DisplayTogether[
  MultipleListPlot[
    {{1,0},{2,1},{3,2}},
    {{1,1},{2,2},{3,3}},
    {{1,2},{2,3},{3,4}},
    {PlotJoined\[Rule]True,
      AxesLabel\[Rule]{"Displacement, mm","Force, N"},
      SymbolShape\[Rule] None}],
  MultipleListPlot[
    {{1.5,2.5},{2,2},{2.5,1.5}},
    {PlotJoined\[Rule]False}]]

DisplayTogether[
  MultipleListPlot[
    {{1,0},{2,1},{3,2}},
    {{1,1},{2,2},{3,3}},
    {{1,2},{2,3},{3,4}},
    {PlotJoined\[Rule]True,
      AxesLabel\[Rule]{"Displacement, mm","Force, N"},
      SymbolShape\[Rule] None,
      PlotLegend\[Rule]{"one","two","three"}}],
  MultipleListPlot[
    {{1,3},{2,2},{3,1}},
    {PlotJoined\[Rule]False}]]



  • Prev by Date: Re: Re: GraphPlot
  • Next by Date: Re: "unload" a package
  • Previous by thread: Re: DisplayTogether & PlotLegend incompatibility
  • Next by thread: Re: DisplayTogether & PlotLegend incompatibility