1
$\begingroup$

Using PlotLegend I would like to show a legend with a mix of lines and markers

see example data and plot command

x = Range[1, 10];
list1 = x^2;
list2 = {1, 3, 5, 2, 6, 8, 2, 8, 9, 4};
list3 = 2 x + 7;
list4 = 15 x - x^2;

ListPlot[{Thread[{x, list1}], Thread[{x, list2}], Thread[{x, list3}], 
Thread[{x, list4}]}, Joined -> {True, True, True, False}, 
PlotMarkers -> {"", "", "", Graphics@Disk[{0, 0}, [email protected]]}, 
PlotStyle -> Thick, Frame -> True, ImageSize -> Large, 
FrameLabel -> {"x", "y", "Example "}, 
PlotLegends -> {"list 1", "list 2", "list 3", "list 4"}]

This creates the plot Example Plot

which is almost what I am after, except I want the circular marker to be evident in the legend.

In the past you could not do this with PlotLegend - I am hoping that this has changed with newer versions of Mathematica.

Here's a solution where you need to manually set all the line colours etc. How to use LineLegend and SwatchLegend together (this is several years old - why I am essentially re-asking the question)

Is anyone aware of a way to do this within a single plot command, so that I do not have to manually set all the line colours etc and can use the underlying defaults?

If the answer is no - that would be good to know, I'll go the manual route.

$\endgroup$

1 Answer 1

3
$\begingroup$

How about:

ListPlot[
    {list1, list2, list3, list4},
    Joined->{True,True,True,False},
    PlotMarkers->{"","","",{Graphics[{Black, Disk[{0,0}]}],.02}},
    PlotStyle->Thick,Frame->True,ImageSize->Large,
    FrameLabel->{{"y",None},{"x","Example"}},
    PlotLegends->LineLegend[
        {"list1", "list2", "list3", "list4"},
        LegendMarkerSize->{20,8}
    ]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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