Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6922

Re: Plot Legends For Side By Side Graphs

From Armand Tamzarian <mike.honeychurch@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Plot Legends For Side By Side Graphs
Date 2011-12-04 07:57 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jbf959$l4d$1@smc.vnet.net> (permalink)
References <jbcpff$bjg$1@smc.vnet.net>

Show all headers | View raw


On Dec 3, 8:17 pm, Brentt <brenttnew...@gmail.com> wrote:
> Hello, I want to produce a plot legend for two Plots, with the same scale=
,
> placed side by side using GraphicsGrid, to export and put in a document.
> Both graphs the same legend, so I only want one legend for both graphs.
> I've been using the "PlotLegends" package but it has some constraints I
> can't figure out how to work around.
>
> I want the legend keys to take on the color of the curves automatically.
> Using the PlotLegend option does this automatically, but it needs to be a=
n
> option in both plots, so I either duplicate the same legend for both plot=
s,
> or the scaling of the plot that I generate the legend for is botched if I
> only generate the legend for one plot.
>
> I've tried using the Legend function to generate a legend in order  to
> expor it to a seperate image file to be placed in the document
> independently.  There doesn't seem to be a way to have the keys take on=
 the
> curve colors automatically, as the PlotLegends option does.
>
> Is there a way to produce one legend for two plots without messing up the
> scaling of the plot, or to use Legend to generate keys that automatically
> take on the colors of the curves they correspond to?

I'd steer clear of the legends package. And to be honest I don't
remember seeing any stuff coming out of Wolfram that uses it.
Having said that, here is a basic solution which may get you started:

stuffToPlot = {Sin[x], Tan[x]};
namesofStuffPlotted = {"Sin", "Tan"};

legend = MapIndexed[
   Row[{Spacer[10],
      Graphics[{AbsoluteThickness[2], ColorData[1, First[#2]],
        Line[{{0, 0}, {1, 0}}]}, AspectRatio -> 0.1, ImageSize -> 30],
       Spacer[5], #1}] &, namesofStuffPlotted];

Labeled[
 GraphicsGrid[{
   {Plot[stuffToPlot, {x, 0, 6}], Plot[stuffToPlot, {x, 0, 6}]}
   }],
 Row@legend, {{Bottom, Center}}]

For a vertical legend just replace Row with Column. If you are using
your own set of colours instead of the indexed ones then you would
need to use MapThread instead of MapIndexed. If you want swatches
instead of lines use Rectangle ...and so on.

Mike

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Plot Legends For Side By Side Graphs Brentt <brenttnewman@gmail.com> - 2011-12-03 09:17 +0000
  Re: Plot Legends For Side By Side Graphs Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-12-04 07:57 +0000
    Re: Plot Legends For Side By Side Graphs JUN <noeckel@gmail.com> - 2011-12-08 10:40 +0000

csiph-web