Message Boards Message Boards

0
|
6744 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to creat a specific/private legend in Mathematica 10 or 9 ?

Posted 10 years ago

A test program, perfect in Earlier Version, but not 9. The problem is, how to do it with Mathematica 10 or 9?

Needs["PlotLegends"] g1 = Plot[Sin[x], {x, 0, 2 Pi}]; legend = Join[{Graphics[{Thick, Blue, Dashed, Line[{{0, 2}, {15, 2}}]}], #1} & @@@ {{Style[ "\[CapitalOmega]=15", FontSize -> 11, FontFamily -> "Times New Roman"]}}, {Graphics[{Thick, Red, Dotted, Line[{{0, 2}, {15, 2}}]}], #1} & @@@ {{Style[ "\[CapitalOmega]=20", FontSize -> 11, FontFamily -> "Times New Roman"]}}, {Graphics[{Thick, Black, DotDashed, Line[{{0, 2}, {6, 2}}]}], #1} & @@@ {{Style[ "\[CapitalOmega]=30", FontSize -> 11, FontFamily -> "Times New Roman"]}}, {Graphics[{Thick, Black, Dashed, Line[{{0, 2}, {6, 2}}]}], #1} & @@@ {{Style[ "\[CapitalOmega]=40", FontSize -> 11, FontFamily -> "Times New Roman"]}}]; ShowLegend[ Show[g1], {legend, LegendPosition -> {0.5, 0.25}, LegendSize -> {0.5, 0.4`}, LegendShadow -> None, LegendBorder -> None}]

POSTED BY: xiaochao Chen
3 Replies
Posted 10 years ago

Thanks for your patience. it's useful for me. In fact, “Legended” may substitute for Needs["PlotLegends`"] in V9/10.

The label "lbl" in Legended[expr,lbl] can be any expression, including graphics.

POSTED BY: Updating Name
Posted 10 years ago

Also note that in your code above Needs["PlotLegends"] should read Needs["PlotLegends`"] -- then the legacy package will load and your code will still work in V10.

POSTED BY: David Keith
Posted 10 years ago

Use the new built-in Plotlegends capability. (Not to be confused with the old PlotLegend package.) I am sure you could work this to an identical form, but here is something which is perhaps suitable:

omegaValues = {15, 20, 30, 40, 50};

plt = Plot[
  Table[Sin[omega x], {omega, omegaValues}] // Evaluate, {x, 0, 
   2 Pi/First[omegaValues]}, 
  PlotStyle -> 
   Table[{Thick, Dashing[.03 {k, 1 - k}]}, {k, .2, 1, .2}], 
  PlotLegends -> LineLegend[omegaValues, LegendLabel -> "Omega"]]

enter image description here

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract