I am generating figures for research paper on mathematica v. 11.0.1. I have some issues with the length of plot legends. The problem is the length of the legend line.

Plot[{x^2, x^3}, {x, 0, 10},  PlotLegends -> {"x^2","x^3"}]

The plot generated with the legends is like the below with equal length of plot markers and the legends aligned.

enter image description here

Even when the plot is carried in different instances and joined using show, it behaves well. But when the plot style is different, then the length of the plot marker line is different. For example,

Show[Plot[x^2, {x, 0, 10},PlotLegends -> {"x^2"}],Plot[x^3, {x, 0, 10}, PlotLegends -> {"x^3"}, PlotStyle -> Directive[Red, Dashed]]]

For the above code, the figure appears like the dashed legend marker is lengthy!

From the discussion in here, LegendMarkerSize is able to solve the problem.

Is there any other simple way to solving this problem in an automated manner?

The second problem is alignment of the legends of list plot and plot.

data = Table[{i, i^2}, {i, 1, 10, 1}];
Show[Plot[x^2, {x, 0, 10}, PlotLegends -> LineLegend[{"line"}]], ListPlot[data, PlotLegends -> LineLegend[{"data"}]]]

For the above code, the legend markers and the text generated are not aligned properly. The figure is shown below.

improper alignment of the legend marker and text

With a little bit of play with Placed with PlotLegends, the text can be aligned. But the position of marker is becoming a problem. What could be the way to align both the text and the marker.

Thank you.


Your Answer

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

Browse other questions tagged or ask your own question.