7
$\begingroup$

fixed in 10.1 (windows)


I'm running into trouble getting the right PlotMarkers in the legend of a ListPlot of many curves. Simple example:

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, 
    PlotMarkers -> {Automatic, Large}, PlotLegends -> Range[20]]

produces:

labeled plot

The legend has the right colors for all curves, but after the fifteenth curve, the markers reset instead of continuing to cycle as they do in the actual plot. If I use PlotLegends->Automatic instead of PlotLegends->Range[20], the legend simply stops with the fifteenth curve.

Any idea what might be going on here?

EDIT: Thanks everybody! There are several different good solutions below. A couple people suggested that this is a bug, so I've added that tag.

$\endgroup$
  • 1
    $\begingroup$ Related: (56327), (66055) $\endgroup$ – Mr.Wizard Mar 11 '15 at 0:31
  • 1
    $\begingroup$ Thanks for the Accept. I included code for the first two examples which I had forgotten. Also, consider using ListLinePlot instead of ListPlot and Joined -> True -- it doesn't help this particular problem but it is shorter and seems to be better supported, e.g. (58808) $\endgroup$ – Mr.Wizard Mar 11 '15 at 21:21
  • $\begingroup$ @Mr.Wizard: Good point about ListLinePlot. I'm in the habit of using Joined->True because it makes it easy to switch among ListPlot, ListLogPlot, ListLogLinearPlot, and ListLogLogPlot, but is there a better way to do this with just ListLinePlot? I guess ScalingFunctions is an (undocumented) option. $\endgroup$ – Daniel Weissman Mar 12 '15 at 1:00
  • $\begingroup$ Good point yourself; I think Joined -> True is the simplest method for the log plot functionality. $\endgroup$ – Mr.Wizard Mar 13 '15 at 5:36
9
$\begingroup$

I believe this can be considered a bug, but it is also related to the (IMHO) non-bug behavior of automatic styling described in PlotLegends won't generate automatically more than 15 labels in v10. We see that if we use PlotLegends -> Automatic the number of legends is limited to the number of styles:

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, 
 PlotStyle -> ColorData[97] ~Array~ 13, PlotMarkers -> {Automatic, Large}, 
 PlotLegends -> Automatic]

enter image description here

In the main plot, and in the legend up to the number colors in PlotStyle, the plot markers are cycled five solid and five outlined. However in the legend this cycle resets after the number of styles is expended. For example it starts again five solid from 14 if we force additional legend items:

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, 
 PlotStyle -> ColorData[97] ~Array~ 13, PlotMarkers -> {Automatic, Large}, 
 PlotLegends -> Range[20]]

enter image description here

The fact that the markers in the plot and legend get "out of sync" appears to be a fault, but understanding it we can solve the problem by providing a sufficient number of styles:

enough = ColorData[#, "ColorList"] & /@ Join[97, 13];

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, 
 PlotMarkers -> {Automatic, Large}, PlotLegends -> Range[20], PlotStyle -> enough]

enter image description here

Alternatively if you make sure that the number of styles is a multiple of ten it will align but there will undesirably be repeats in the legend.

$\endgroup$
1
$\begingroup$

Try making a list of all the PlotMarkers:

 ListPlot[
     Table[{j, i}, {i, Range[20]}, {j, Range[3]}],
     Joined -> True,
     PlotStyle -> Table[Hue[i/20], {i, 20}],
     PlotMarkers -> (Text[Style[#, 16]] & /@ CharacterRange["a", "z"]),
     PlotLegends -> Range[20]
         ]

enter image description here

I suspect that the default list of PlotMarkers has only 15 entries (in v. 10.0.0).

$\endgroup$
  • 1
    $\begingroup$ This doesn't seem to address the OP's problem. The 20 plot markers on the plot itself are all distinguishable. $\endgroup$ – m_goldberg Mar 10 '15 at 23:45
2
$\begingroup$

It works fine in MMA 9:

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True,
  PlotMarkers -> Automatic, PlotLegends -> LineLegend[Range[20]]]

enter image description here

It looks like a bug in MMA v10

$\endgroup$
3
$\begingroup$
markers = {#, Large} & /@ PadRight[#, 20, #] &@ Graphics`PlotMarkers[][[All, 1]];

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, 
    PlotMarkers -> markers, PlotLegends ->LineLegend[Range[20], LegendMarkers ->  markers]]
$\endgroup$
5
$\begingroup$

PlotMarkers are passed to the legends via the LegendMarkers option. Here it looks like only 15 markers are being passed in, e.g.

In[3]:= plot = ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], 
   Joined -> True, PlotMarkers -> {Automatic, Large}, 
   PlotLegends -> Range[20]];

In[4]:= Cases[plot, HoldPattern[LegendMarkers -> l_] :> l, -1]

Out[4]= {{{"\[FilledCircle]", Large}, {"\[FilledSquare]", Large}, 
 {"\[FilledDiamond]", Large}, {"\[FilledUpTriangle]", Large}, 
 {"\[FilledDownTriangle]", Large}, {"\[EmptyCircle]", Large}, 
 {"\[EmptySquare]", Large}, {"\[EmptyDiamond]", Large}, 
 {"\[EmptyUpTriangle]", Large}, {"\[EmptyDownTriangle]", Large}, 
 {"\[FilledCircle]", Large}, {"\[FilledSquare]", Large}, 
 {"\[FilledDiamond]", Large}, {"\[FilledUpTriangle]", Large}, 
 {"\[FilledDownTriangle]", Large}}}

So, while Mr.Wizard's suggestion is the reliably correct method, I would suggest something different. LegendMarkers is cyclic in application, so you could simply reduce the number of markers used to 10, e.g.

plot /. HoldPattern[LegendMarkers -> l_] :> (LegendMarkers -> l[[;; 10]])

enter image description here

$\endgroup$
2
$\begingroup$

This has been fixed in 10.1

Mathematica graphics


Mathematica graphics

code

ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], 
Joined -> True, PlotMarkers -> {Automatic, Large}, PlotLegends -> Range[20]]
$\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.