Tag Info

Hot answers tagged

13

Bob Hanlon's answer works very well, but in some ways it is the hard way of doing things. If you have v9 or v10, then it is arguably easier to use the legend constructs within it. Similar to his answer, we get the image and element names: img = Import["ExampleData/1PPT.pdb", "Rendering" -> "BallAndStick", ImageSize -> 500]; elements = ...


10

bas = Import["ExampleData/1PPT.pdb", "Rendering" -> "BallAndStick", ImageSize -> 500]; elements = Import["ExampleData/1PPT.pdb", "ResidueAtoms"] // Flatten // Union; legend = GraphicsColumn[{ {Graphics[{#[[1]], Disk[{0, 0}, 1]}, ImageSize -> 10], #[[2]]} & /@ Thread[{ ElementData[#, "IconColor"] & /@ elements, ...


10

ListPlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}], PlotLegends ->PointLegend[ (Style[#, 40] & /@ {"sin(x)", "cos(x)"}),Alignment->Center]] Update: As noted by rcollyer in the comments Alignment is an undocumented option for PointLegend. As an alternative, the following old Pane trick works without relying on an undocumented option: ...


6

For ChartLegends, although the documentation does not mention any values other than "Row" and "Column" for the option LegendAppearance, it turns out you can also use this option to set the LegendMarkerSize BarChart[{{1, 2, 3}, {1, 3, 2}}, ChartStyle -> {Red, Green, Blue}, LegendAppearance -> {LegendMarkerSize -> 20}, ChartLegends -> {"a", ...


6

I always do it like this: cm = 72/2.54; BarChart[{{1, 2, 3}, {1, 3, 2}}, ChartLegends -> SwatchLegend[{"a", "b", "c"}, LegendMarkerSize -> 20], ImageSize -> 4 cm] top: code from your question, bottom: this code The colors of the legend are inherited from the BarChart object: BarChart[{{1, 2, 3}, {1, 3, 2}}, ChartStyle -> {Red, Green, ...


6

The following works in both v9 and v10: style = Directive[Thick, Black]; ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1}, ContourStyle -> Directive[Thick, Black, Opacity[1]], FrameStyle -> style, PlotLegends -> BarLegend[Automatic, Method -> {FrameStyle -> style}]] The idea to use the (undocumented) Method option comes from inspecting the ...


6

A reasonable workaround is to use SwatchLegend with LegendMarkers set: ListPlot[ Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}], PlotLegends -> SwatchLegend[{"sin(x)", "cos(x)"}, LabelStyle -> 40, LegendMarkers -> "Bubble" ] ]


4

I can confirm the shift occurs even without the special default styling in your plot (version 9). Your issue stems directly from the use of a special font marker \[FilledSquare] in a PointLegend instead of just using a SwatchLegend. The following does not have the shifting problem. Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, PlotLegends -> ...


4

ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1}, ContourStyle -> Directive[Thick, Black, Opacity[1]], FrameStyle -> Directive[Thick, Black], PlotLegends -> BarLegend[Automatic]] /. HoldPattern[PlotRangePadding -> Automatic] :> Sequence[FrameStyle -> Thick, PlotRangePadding -> None]


2

This is not any improvement over rm-rf. In v9 you can also use Legended: Module[{f, col = {Red, Blue}, exp, leg, pm = {\[DiamondSuit], 20}}, f[legend_] := Framed[legend, FrameStyle -> Red, RoundingRadius -> 10, FrameMargins -> 5, Background -> LightBlue]; exp = GraphicsGrid[ Partition[ Table[ListPlot[{Sqrt[Range[0, 50, 5]], ...


2

Verbeia already gave you more robust alternative methods, but in direct answer to the question I believe this is due to the use of a font glyph for \[FilledSquare] and the interaction of these two issues: Point Renderings Slightly Off in Mathematica Poor anti-aliasing in Rotated text with ClearType on In summary: Font glyphs are subject to alignment ...


2

You can also do this way: plot = MatrixPlot[RandomReal[{0, 1}, {10, 10}], ColorFunction -> ColorData["GrayTones"], ImageSize -> 200, PlotLegends -> Automatic]; plot /. Rational[x_, y_] :> ScientificForm[N[x/y]] Or combine it with Brett's answer so that it works both for large and small numbers: plot = MatrixPlot[100000000 ...


1

Here's a workaround for the lazy (and those trying to copy from a Manipulate output): Copy the Legend like you would copy text Edit the plot via Drawing Tools (Right-Click on the plot, then "Drawing Tools") Insert a text frame, paste the Legend and resize and move it as you like Hope this helps.



Only top voted, non community-wiki answers of a minimum length are eligible