# PlotLegends in Show with listlog

I am struggling with proper plot legends in Show command for two plots created by LogListPlot command.

a = {{5692/5693, 8249/8250, 8158/8159, 7078/7079, 1999/2000,
1599/1600, 3549/3550, 6093/6098, 7997/8000, 1999/2000}, {10924/
8125, 14473/8103, 22362/9095, 30739/9000, 37649/8079, 51953/8099,
53369/6000, 69907/5602, 52049/3000, 47489/2000}, {4507/2931,
21887/8805, 35546/8831, 64281/9826, 47396/4395, 66769/3721, 62425/
2119, 62209/1258, 3257/39, 29938/223}, {1018/575, 973/313, 309/55,
36317/3500, 158677/8351, 76792/2131}};
b= {{Sqrt[2], Sqrt[2], Sqrt[2], Sqrt[2], Sqrt[2], Sqrt[2], Sqrt[2], Sqrt[
2], Sqrt[2], Sqrt[2]}, {2 Sqrt[2], 4, 4 Sqrt[2], 8, 8 Sqrt[2], 16,
16 Sqrt[2], 32, 32 Sqrt[2], 64}, {3 Sqrt[2], 3 Sqrt[6], 9 Sqrt[2],
9 Sqrt[6], 27 Sqrt[2], 27 Sqrt[6], 81 Sqrt[2], 81 Sqrt[6],
243 Sqrt[2], 243 Sqrt[6]}, {4 Sqrt[2], 8 Sqrt[2], 16 Sqrt[2],
32 Sqrt[2], 64 Sqrt[2], 128 Sqrt[2]}};

Show[ListLogPlot[Table[a[[DD - 1]], {DD, 3, 5}], Joined -> True,
PlotMarkers -> Automatic,
PlotLegends -> {"D = 2", "D = 3", "D = 4", "D = 5"}],
ListLogPlot[Table[b[[DD - 1]], {DD, 3, 5}],
PlotMarkers -> {"*", "O", "A", "B"},
PlotLegends -> {"D = 2 UB", "D = 3 UB", "D = 4 UB", "D = 5 UB"},
Joined -> True], PlotRange -> All,
AxesLabel -> {"N", "Log of something"}]


It gives the plots alright with different plotmarkers but doesn't show different legends with different symbols. My output is

Anything missing here? Thanks

• Did the correction. Hopefully it will work now. – dbm Mar 3 '15 at 0:07
• When I run this, I get two different legends (with different symbols). Can you post the output you get and explain why it is inadequate? – djp Mar 3 '15 at 0:10
• I have put the figure I get in my original question now. – dbm Mar 3 '15 at 0:15
• Thanks. When I run your code (10.0.2 / Mac) I get different legends, i.e. the correct behaviour. (The O and the A show up at 3 UB and 4 UB.) It's a bug. – djp Mar 3 '15 at 0:23
• Works fine with 10.0.2.0 under Windows 8.1 (64 bit) too. – bbgodfrey Mar 3 '15 at 1:09

There are some issues with of lines but perhaps this is helpful.

ListLogPlot[Join[a[[#]] & /@ Range[2, 4], b[[#]] & /@ Range[2, 4]],
Joined -> True,
PlotMarkers -> {{\[FilledCircle], 12}, {\[FilledSquare],
12}, {\[FilledDiamond], 12}, "*", "O", "A"},
PlotLegends ->
PointLegend[
Automatic, {"D = 2", "D = 3", "D = 4", "D = 2 UB", "D = 3 UB",
"D = 4 UB"}]]


The following modification of the setting for PlotLegends works in Version 9.0.1.0 (Windows 8 x64):

Show[ListLogPlot[Table[a[[DD - 1]], {DD, 3, 5}], Joined -> True, PlotMarkers -> Automatic,
PlotLegends -> LineLegend[Automatic, ls = {"D = 2", "D = 3", "D = 4", "D = 5"},
LegendMarkers -> Automatic]],
ListLogPlot[Table[b[[DD - 1]], {DD, 3, 5}], Joined -> True, PlotMarkers -> {"*", "O", "A", "B"},
PlotLegends -> LineLegend[Automatic, # <> " UB" & /@ ls, LegendMarkers -> Automatic]],
PlotRange -> All, AxesLabel -> {"N", "Log of something"}]


I usually do the following trick by taking advantage of the overwriting of Plot properties of the 1st plot by the 2nd plot in show:

Show[
ListLogPlot[Table[a[[DD - 1]], {DD, 3, 5}], Joined -> True, PlotMarkers -> Automatic],
ListLogPlot[Join[Table[Null, {3}], Table[b[[DD - 1]], {DD, 3, 5}]],
PlotMarkers -> Join[Table[Automatic, {3}], {"*", "O", "A", "B"}],
PlotLegends -> {"D = 2", "D = 3", "D = 4", "D = 2 UB", "D = 3 UB", "D = 4 UB"}, Joined -> True], PlotRange -> All,
AxesLabel -> {"N", "Log of something"}]


With this approach (covering the number of datasets from the 1st plot by inserting Null statements into the data list of the 2nd plot => see above) you can set all properties for the plot by Options in the 2nd plot. You just need to ensure that the functions in the 1st plot have the same plot style than the styles of the legend (set by the 2nd plot).

This works for Plot statements too, by the way...