Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.9K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Building a legend for a single plot with different types of markers?

Posted 4 years ago

I use Plot to generate a plot of a function and I surimpose to it points of different nature thru the Epilog option.

func = Sin[x];
ptsInfl = Solve[D[func, {x, 2}] == 0];  (* inflection points*)
ptsExtrm = Solve[D[func, {x, 1}] == 0] ;(* extremum  points*)
t1 = Table[
   Point[{#[[2]], func /. #}] /. C[1] -> i & /@ ptsInfl[[All, 1]], {i,
     0, 1}];
t2 = Table[
   Point[{#[[2]], func /. #}] /. C[1] -> i & /@ 
    ptsExtrm[[All, 1]], {i, 0, 1}];
Plot[{func}, {x, 0, 3 Pi},  
 Epilog -> {Red, PointSize@Large, t1[[#]] & /@ Range@Length@t1, Green,
    t2[[#]] & /@ Range@Length@t2}]

How can I construct a framed legend to the example above with two rows, one having a blue line with a green point astride it and beside it some text, and another one with a blue line with a red point astride it plus some text ? I am expecting to get something similar with the options PointLegend and PlotMarkers of the function ListLinePlot .

Wojtek

POSTED BY: wojtek potocki
2 Replies
Posted 4 years ago

Hi Wojtek

Something like this?

Plot[{func}, {x, 0, 3 Pi},
 PlotLegends ->
  LineLegend[{Blue, Blue}, {"Green", "Red"},
   LegendMarkers -> {Style["\[Bullet]", Green, 30], Style["\[Bullet]", Red, 30]},
   LegendMarkerSize -> {30, 15},
   LegendFunction -> (Framed[#, RoundingRadius -> 4] &)],
 Frame -> True,
 ImageSize -> 500,
 Epilog -> {Red, PointSize@Large, t1[[#]] & /@ Range@Length@t1, Green, t2[[#]] & /@ Range@Length@t2}]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Your answer is perfect. Thanks..

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