Hot answers tagged

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

There is a lot to your question, but first some preliminaries. Instead of crafting your own markup for degrees Celsius, I would use the Quantity framework as it will handle the markup for you, and in my opinion looks better: Quantity[-{91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49}, "DegreesCelsius"] which you can use directly as the ...


10

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


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

makeContours[barLegend_BarLegend] /; (Length[barLegend] =!= 2) := barLegend makeContours[barLegend_BarLegend] := Module[{colorScheme = barLegend[[1]], contourCount = barLegend[[2]]}, If[IntegerQ[contourCount] && contourCount > 11 && DataPaclets`ColorDataDump`colorSchemeNameQ[colorScheme], ToExpression[ ...


8

In 10.x, the simplest thing is to specify the PlotMarkers directly, but as noted, the legends ignore ImageSize if specified within the graphic. The correct way to do this is to use the {{g1, s1}, {g2, s2} ...} form of PlotMarkers, e.g. ListPlot[Table[Accumulate@RandomReal[1, 10] + i, {i, 2}], PlotMarkers -> {{Graphics[{Disk[]}], 1/4}, ...


8

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


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


8

Show already combines these if you include the legends in your assignments. x1 = Legended[Show[Graphics3D[{Opacity[0.6], Red, Sphere[]}]], SwatchLegend[{Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}]]; x2 = Legended[Show[Graphics3D[{Opacity[0.4], Blue, Cylinder[]}]], SwatchLegend[{Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}]]; x3 = ...


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


7

Legended[Show[{g1, g2, g3}], SwatchLegend[{RGBColor[1, 0, 0], RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 0, 0], RGBColor[0, 0, 1], RGBColor[0, 1, 0]}, {"x\[Rule]ξ", "ξ≡ξ'", "ξ'\[Rule]x'", "y\[Rule]η", "η\[Rule]η'", "η'\[Rule]y'", "z≡ζ", "ζ\[Rule]ζ'", "ζ'≡z'"}, LegendLayout ...


7

you can also do it like this: Legended[Show[{g1, g2, g3}], Grid[{SwatchLegend @@@ {{{Red, Red, Red}, {"x\[Rule]ξ", "y\[Rule]η", "z≡ζ"}}, {{Blue, Blue, Blue}, {"ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'"}}, {{Green, Green, Green}, {"ξ'\[Rule]x'", "η'\[Rule]y'", "ζ'≡z'"}}}}]]


7

Code: Plot[ {Log[x], Log[Sin[x]]}, {x, -1, 23}, PlotLegends -> Placed[{Style[Log[x], Red], Style[Log[Sin[x]], Blue]}, {0.8, 0.8}], PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}}, LabelStyle -> {FontSize -> 11}] Output: Alternative: Plot[ {Log[x], Log[Sin[x]]}, {x, -1, 23}, PlotLegends -> ...


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

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

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


6

In Mathematica 10.3 you can use LineLegend. I myself have never liked to have a legend within the plot, so I insert it in a grid. depth4 = Range[20]^3; style1 = Directive[Purple]; plot = ListLogLogPlot[Sort[depth4], PlotRange -> {{1, 50000}, {1, 50000}}, Joined -> True, PlotStyle -> style1, BaseStyle -> {FontSize -> 14}]; style2 = ...


6

I'm using version 10.2, and it seems that the legends from the initial plots work just fine with Show depth4 = Range[20]^3; plot = ListLogLogPlot[Sort[depth4], PlotRange -> {{1, 50000}, {1, 50000}}, Joined -> True, PlotStyle -> {Purple}, BaseStyle -> {FontSize -> 14}, PlotLegends -> {"plot"}]; line = LogLogPlot[11024 ...


6

I have just removed capital variables. I have interpreted the aim as having distinct 'labeling' for functions m and p (red, purple) and for values of rho. In this example dashing is used. tmp = 0.1316; p[T_, α_, β_, ρ_]:= Sqrt[(α^2 β - T α^2 β+t α^2 β ρ -tmp α^2 β ρ)/(α^2 β - ρ^2)]; m[T_, α_, β_, ρ_]:= Sqrt[(t α^2 β+tmp α^2 β-(ρ (α^2 β-t α^2 β + t α^2 β ...


5

I propose using the lower-level System`PlotThemeDump`resolvePlotTheme to find the information you need. This reveals the color scheme number itself rather than resolving to a list of Directives. You must give the plot function name as a String. The key you are looking for is "DefaultColor: Themes`ThemeRules; (* preload PlotThemes subsystem *) ...


5

For version 10.x the answer can be found in the documentation: ListPlot[Table[Accumulate@RandomReal[1, 10] + i, {i, 2}], PlotMarkers -> {{"\[FilledCircle]", 20}, {"\[FilledSquare]", 10}}, Joined -> True, PlotLegends -> {"line1", "line2"}] This should work for graphics objects like the OP used too.


5

"Expressions" for legend in ListPlot family is used because of Association. With Association input, the plot will automatically pick up the keys as legends. Here is an example: ListPlot[<|"A"->{1,2,3},"B"->{2,3,4}|>] SetOptions is to set the default values to options but it doesn't guarantee that the settings will be used by the plot since ...


5

There is an easier answer to this (esp. if you don't want to custom-specify colors), at least in version 10, found as the answer to this question: LegendLayout -> {"Column", 1}] All credit goes to MinHsuan Peng who answered that question, I just reposted here because I found this page first and thought other people searching for this would like to ...


5

Works for me {p1, p2, p3, p4} = Accumulate /@ RandomVariate[NormalDistribution[0, 1], {4, 50}]; ListLinePlot[{p1, p2, p3, p4}, PlotLegends -> {"a", "b"}] What version of Mathematica are you using? ListPlot works fine, though of course by default you get dots not an unbroken line.


5

LegendBorder doesn't exist. Use LineLegend ListLinePlot[{series1, series2, series3}, PlotStyle -> {{Thickness[Large], GrayLevel[0]}, {Dashing[{Small, Small}], GrayLevel[0]}, {Dotted, Red}}, Frame -> True, GridLines -> Automatic, FrameLabel -> {"x", "y"}, PlotLegends -> LineLegend[{Black, {Gray, ...


5

To avoid redundant color swatches: g1 = Graphics3D[{Opacity[0.6], Red, Sphere[]}]; g2 = Graphics3D[{Opacity[0.4], Blue, Cylinder[]}]; g3 = Graphics3D[{Green, Cone[]}]; Legended[Show[g1, g2, g3], SwatchLegend[ {Red, Blue, Green}, {Column[{"", "x\[Rule]ξ", "y\[Rule]η", "z≡ζ", ""}], Column[{"", "ξ≡ξ'", "η\[Rule]η'", "ζ\[Rule]ζ'", ""}], ...


5

Use Row to build the legend text. funcs = Table[With[{k = k}, k # &], {k, 0, 3, 1/2}]; legends = Table[Row[{"D = ", N @ k}], {k, 0, 3, 1/2}]; Plot[Evaluate @ Through[funcs[x]], {x, 0, 5}, PlotLegends -> legends]


5

I think the behavior of LineLegend exhibited in the question, if not a bug, is within an epsilon of a bug. Consider that the following all succeed ... LineLegend[{{Red, Dashed}, Green, Blue}, {"r", "g", "b"}] LineLegend[{{Red, Dashed}, {Green, Dashed}, Blue}, {"r", "g", "b"}] LineLegend[{Directive[Red, Dashed], {Green, Dashed}, {Blue, Dashed}}, {"r", ...


5

Use the option LegendShadow -> None From Plot Legends documentation LegendShadow is an option for Legend that specifies the shadowing drawn around the legend.



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