Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Tool for creating plot legends
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Christopher O. Young

Posts: 182
Registered: 2/13/11
Tool for creating plot legends
Posted: Feb 11, 2012 3:50 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

This will handle the general case of combined plots and let you
substitute in different function lists and colors, as well as move the
legend around and changing the spacings in the legend. Shouldn't be too
hard to adapt it to more general styles for the plotting and legend.
The Legend package won't automatically pick up the styles from the plot
except in the case where there's only one kind of plot. So in this
case, one should enter all the style definitions into a variable to be
shared by the plots and by the Legend.

http://home.comcast.net/~cy56/Mma/LegendTool.nb
http://home.comcast.net/~cy56/Mma/LegendToolPic.png

Chris Young
cy56@comcast.net


DynamicModule[
{
graphic, (* for the graphics in the legend *)

colors = {Red, Yellow, Green},
fncs = {Sin, Cos, Log},
plotNames = {"sine", "cosine", "log"}
},

graphic[c_] := Graphics[{
c,
Line[{{-1, 0}, {1, 0}}],
PointSize[Medium], Point[{0, 0}]
}];

Manipulate[
ShowLegend[
Show[

Plot[
Table[f[x], {f, fncs}] // Evaluate,
{x, 0, 10},
PlotStyle -> colors
],

ListPlot[
Table[
{x, f[x]}, {f, fncs},
{x, 0, 10, 0.5}
],
PlotStyle -> colors,
PlotMarkers -> Graphics[{PointSize[Medium], Point[{0, 0}]}]
],

PlotRange -> {{0, 10}, {-2, 2}},
AspectRatio -> 4/10
],

{
Table[{graphic[colors[[i]]], plotNames[[i]]}, {i, 3}],

LegendPosition -> {1.1, -.4},
LegendSize -> {xLnth, yLnth},
ShadowBackground -> LightGray,
LegendSpacing -> spacing,
LegendTextOffset -> {textOffX, textOffY},
LegendTextSpace -> textSp,
LegendLabelSpace -> labelSp,
LegendBorderSpace -> borderSp
}
],
{{xLnth, 0.75}, 0, 2, 0.25},
{{yLnth, 0.5}, 0, 2, 0.25},
{{spacing, 0}, -2, 2, 0.25},
{{textOffX, 0}, -1, 1, 0.25},
{{textOffY, -0.25}, -1, 1, 0.25},
{{textSp, 0.5}, -1, 2, 0.25},
{{labelSp, 0}, -1, 2, 0.25},
{{borderSp, 0.5}, 0, 2, 0.25}
]
]





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.