4
$\begingroup$

I am trying to make a legend comprised of both the plot's marker symbol and a line. Specifically, I am hoping to have a legend that looks like the line is crossing through the marker. My current code only shows a line:

Function1 = Exp[-0.03*g100];

Plot1 = Plot[Function1, {g100, 0.000001, 100}, ImageSize -> Large, PlotRange -> {0, 1}, 
   Frame -> {{True, False}, {True, False}}, 
   PlotLegends -> 
    Placed[{Style["test", FontSize -> 20,
        Black]}, {0.9, 0.85}]];
Plot2 = ListPlot[
   Thread[{Range[1/20, 1, 1/20], {0.228, 0.379, 0.433, 0.515, 0.557, 
      0.567, 0.621, 0.624, 0.637, 0.661, 0.663, 0.655, 0.613, 0.601, 
      0.578, 0.512, 0.484, 0.459, 0.399, 0.38}}], DataRange -> {0, 1},
    PlotMarkers -> {"\[FilledCircle]", 15}, PlotRange -> {0, 0.4}];
Show[Plot1, Plot2]

Is there a solution to this problem, despite the fact that the markers are associated with a data set that is independent of Function1?

$\endgroup$
2
  • 4
    $\begingroup$ use PlotLegends -> Placed[LineLegend[{Style["test", FontSize -> 20, Black]}, LegendMarkers -> {Automatic, 12}], {0.9, 0.85}] in Plot[...]? $\endgroup$
    – kglr
    Apr 16 at 3:13
  • $\begingroup$ @kglr Thank you so much!! $\endgroup$ Apr 16 at 4:01

1 Answer 1

2
$\begingroup$

For me, the obvious step of adding a PlotLegends argument to Plot2 does what I think you are asking for

Function1 = Exp[-0.03*g100];

Plot1 = Plot[Function1, {g100, 0.000001, 100}, ImageSize -> Large, 
   PlotRange -> {0, 1}, Frame -> {{True, False}, {True, False}}, 
   PlotLegends -> 
    Placed[{Style["test", FontSize -> 20, Black]}, {0.9, 0.85}]];
Plot2 = ListPlot[
   Thread[{Range[1/20, 1, 1/20], {0.228, 0.379, 0.433, 0.515, 0.557, 
      0.567, 0.621, 0.624, 0.637, 0.661, 0.663, 0.655, 0.613, 0.601, 
      0.578, 0.512, 0.484, 0.459, 0.399, 0.38}}], DataRange -> {0, 1},
    PlotMarkers -> {"●", 15}, 
   PlotLegends -> 
    Placed[{Style["test 2", FontSize -> 20, Black]}, {0.9, 0.85}], 
   PlotRange -> {0, 0.4}];
Show[Plot1, Plot2]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.