Tag Info

Hot answers tagged

31

Use the individual legends as tick labels: dates = Through[{First, Last}@#] & /@ res {{1769, 1821}, {1775, 1817}, {1770, 1831}, {1818, 1883}, {1777, 1855}, {1766, 1817}, {1870, 1924}} names={"Napoleon Bonaparte", "Jane Austen", "Hegel", "Marx", "Gauss", "Madame de Stael", "Lenin"}; llpd = MapIndexed[Thread@{#, First@#2} &, dates]; legends ...


17

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 = ...


17

We may observe that the automatically generated legend limits the number of legend items to the number of available colors in the given color scheme. Using this utility function: plot[scheme_] := Plot[Evaluate[Range[20] + x], {x, -5, 5}, PlotLegends -> "Expressions", PlotStyle -> scheme] Observe the result for indexed color scheme #42 which has ...


12

This is not a bug. I think that this is not a bug, see addendum. Based on my (limited!) experience, I believe that LineLegend and PointLegend are in fact the very same thing with differing default options. LineLegend has Joined -> True while PointLegend has Joined -> False by default, but otherwise they are identical. The syntax you used, i.e. ...


11

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, ...


11

You have to add the index for the colors to LineLegend Legended[Grid[{{Show[oniplot], Show[cpplot]}}], LineLegend[97, {"factor = 2", "factor = 3", "factor = 4", "factor = 5"}]] In order to have the legend above the plots and with markers: Legended[GraphicsGrid[{{oniplot, cpplot}}], Placed[LineLegend[97, Array["factor = " <> ToString@# ...


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: ...


10

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 ...


9

There is an undocumented form of LegendLayout that is useful here: LegendLayout -> {"Column", noOfColumns} similarly for "Row" and their reversed cousins. So, in your case I would use LegendLayout -> {"Column", 2} giving Obviously, you do not have to include the color list when you pass it to PlotLegends.


9

data3 = Style[{##}, ColorData["Rainbow"][Abs[(#1 - 0.5)] + Abs[1/10 (#2 - 5)]]] & @@@ data; Legended[ListPlot[data3, PlotStyle -> PointSize[0.01]], BarLegend["Rainbow"]] Update for your question in the comment: The color function ColorData["Rainbow"] ranges from 0 to 1 so the value has to be used within this range. Abs function ...


9

This was more involved than I expected. First, you need to set the ColorFunction to encompass the full range, ColorData[{"BlueGreenYellow", {0, 10}}] Interestingly, I did not know about that form of ColorData until earlier this week, so I recommend reading through the Details section closely. Now, to use this within ContourPlot, you need to set ...


9

Somehow the AbsolutThickness you specified gets replaced by a default value of AbsoluteThickness[0.2]. This misbehavior can be corrected by replacing the incorrect value with your specification. Needs["GeneralUtilities`"] PlotLegends; (*preload definitions*) Cell[BoxData[ MakePasteBox@ BarLegend[{"SunsetColors", {0, 1}}, LabelStyle -> ...


8

Use colors=(("DefaultPlotStyle"/.(Method /. Charting`ResolvePlotTheme["Scientific" , ListLinePlot]))/. Directive[x_,__]:>x) to get the colors used in the "Scientific" plot theme. Then use colors as the first argument of LineLegend: Column[{ Row[{Style["Data from experiment 5B", FontFamily -> "Times", FontSize -> 12]}, Alignment -> ...


8

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, ...


8

Yes, and yes! You do need to enter all the names of the compounds once (as in the list compoundName), but after that, you can make Mathematica do the rest. As Guess who it is suggests, you can make these names considerably more compact by specifying the chemical formulae. On a side note, Mathematica has access to curated chemical data via ChemicalData, ...


7

Borrowing from kguler the legends legends = MapIndexed[ SwatchLegend[{ColorData[{"Rainbow", {1, 7}}][## & @@ #2]}, {#}, LegendMarkerSize -> {{10, 10}}] &, names]; p1 = ListLinePlot[par, ColorFunction -> "Rainbow", Ticks -> {Range[1750, 1980, 10], Automatic}, PlotRangePadding -> {{5, 50}, {0, 1}}, GridLines -> ...


7

f@x_ := ColorData["VisibleSpectrum"][Rescale[x, {0, 1}, {380, 750}]]; Plot3D[ Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, ColorFunction -> f, PlotLegends -> BarLegend[{f@# &, {0, 1}}]]


7

points = Table[{x, .5 x^2 - 3 + RandomReal[]}, {x, -3, 3}]; Show[{ListPlot[points, PlotLegends -> {"Experiment"}], Plot[{.5 x^2 - 3}, {x, -3, 3}, PlotStyle -> Red, PlotLegends -> {"Model"}]}]


7

Using either Swatchlegend, PointLegend, LineLegend, Barlegend you can easily generate a legend like you would get in a plot. SwatchLegend[{Red, Green, Blue}, {"red", "green", "blue"}] PointLegend[{Red, Green, Blue}, {"red", "green", "blue"}] LineLegend[{Red, Green, Blue}, {"red", "green", "blue"}] BarLegend["Rainbow"] Non-default styles are ...


7

data = Transpose[{RandomReal[{0, 1}, 10000], RandomReal[{0, 10}, 10000]}]; Legended[Graphics[{Function[{x, y}, {ColorData["Rainbow"][ Norm[{x, y/10} - {0.5, 0.5}]/Sqrt[0.5]], Point[{x, y}]}] @@@ data, {Red, PointSize[0.04], Point[{0.5, 5}]}}, AspectRatio -> Full, Frame -> True], BarLegend["Rainbow"]]


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

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" ] ]


6

To me it looks like there is a bug in the Implementation of BarLegend. When the the number of contours increases there is not only a switch from discrete contours to a continuous gradient (this behavior is documented), but also a change in the scaling (that's the bug). colorf = Blend[{{0, Red}, {20, Yellow}, {40, Green}}, Round[#, 0.1]] &; ...


6

This is a variation of Plot draws list of curves in same color when not using Evaluate. By using /. the head of the first argument is ReplaceAll rather than a List, and the styling subroutine of ParametricPlot does not know what to do with it. Make the substitutions part of the definitions and you get this: N1[a_] := (4 d)/(π a) ...


6

You should use built-in option PlotLegends now (note the s in the end). From MathGroup archive: WRI forgot to change the documentation PlotLegends/guide/PlotLegendsPackage so as to say it's obsolete and to refer to the new PlotLegends built into the kernel.


6

First, a function to produce dots to be used as filling: dotsF[n_: {50, 50}, sz_: Medium, clr_: LightGray] := With[{g = Tuples[{Range[n[[1]]], Range[n[[2]]]}]}, Graphics[{clr, PointSize[sz], Point@g}, ImagePadding -> 0, PlotRangeClipping -> False, PlotRangePadding -> 0, AspectRatio -> 1]] dotsF[{10, 10}, .1, Green] It will be more ...


6

Update: Generate a separate legend with the default color scheme and export it: lineleg = LineLegend["DefaultPlotStyle"/. (Method/. Charting`ResolvePlotTheme[Automatic, ListLinePlot]), {"leg1", "leg2", "leg3"}]; Export["plotlegend.pdf",lineleg] To get the default colors associated with various PlotThemes you can use the function ...


6

You can do this with the old-style plot legends package. Quiet@Needs["PlotLegends`"]; ShowLegend[Show[Plot[{x, x^2}, {x, 1, 2}, Frame -> True], ListPlot[Table[{i, i}, {i, 0, 2, 0.1}], Frame -> True]], {{{Graphics[{ColorData[97, 1], Thick, Line[{{0, 0}, {2, 0}}]}], Style["Aa", 12, FontFamily -> "Helvetica"]}, {Graphics[{ColorData[97, 2], ...


6

This is an addendum to rcollyer's answer. I'll delete this should he choose to incorporate the gist of this answer into his. I think there are better choices to be made for the PlotLegends and ColorFunction options. Consider the following: ContourPlot[x y, {x, 0, 2}, {y, 0, 2}, PlotLegends -> BarLegend[{Automatic, {0, 4}}, {Automatic, 8}], ...



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