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

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.


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

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


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

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

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

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

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


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


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


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


5

Update: A much easier way is to use single LineLegend with point and line elements: mixedlegend = LineLegend[{White, White, Blue, Black}, {"Experimental data 1", "Experimental data 2", "Theoretical line for data 1", "Theoretical line for data 2"}, LegendMarkers -> {Graphics[{Red, Disk[]}], Graphics[{Orange, Disk[]}], None, None}] ...


5

You can change the legend using the LegendMarkers option to an explicitly constructed LineLegend. The points are a bit of a hack, but you can always explicitly create them as an Epilog collection of points. I couldn't work out which colour scheme is the default in version 10, so I used the first indexed colour scheme, which replicates the default styles used ...


5

PlotMarkers are passed to the legends via the LegendMarkers option. Here it looks like only 15 markers are being passed in, e.g. In[3]:= plot = ListPlot[Table[{j, i}, {i, Range[20]}, {j, Range[3]}], Joined -> True, PlotMarkers -> {Automatic, Large}, PlotLegends -> Range[20]]; In[4]:= Cases[plot, HoldPattern[LegendMarkers -> l_] :> l, ...


5

You can use the (afaik undocumented) option "Ticks" ContourPlot[Sin[x] Cos[y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, Contours -> {Automatic, 10}, ColorFunction -> "Rainbow", PlotLegends -> BarLegend[Automatic, None, "Ticks" -> {{-1, "cold"}, {0, "ok"}, {1, "hot"}}]] Note: You can also use Ticks instead of "Ticks" and ignore the red highlighting ...


5

Legended[ContourPlot[x y, {x, 0, 1}, {y, 0, 1}], Placed[BarLegend[{ColorData["M10DefaultDensityGradient"], {0, 1}}, LegendLayout -> "Row"], Below]] I found the name of the color scheme by evaluating plot = ContourPlot[x y, {x, 0, 1}, {y, 0, 1}, PlotLegends -> Automatic] and looking at the expression of the result. As Legended accepts two ...


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

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

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



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