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


11

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. PlotLegends; (*preload definitions*) Cell[BoxData[ MakeBoxes@ BarLegend[{"SunsetColors", {0, 1}}, LabelStyle -> {FontSize -> 12}, ...


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[ MakeBoxes[barLegend]...


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

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


7

This looks like a bug. Please report it to Wolfram Support. A simple workaround is to specify your own colour function. ArrayPlot[{{1, 0.1, 0}, {0.1, 0, 0}}, PlotLegends -> Automatic, ColorFunction -> (GrayLevel[1 - #] &)]


7

ClearAll[table] table[pairs_] := Module[{p = pairs}, p[[3, 2]] = SpanFromAbove; p[[4, 2]] = SpanFromAbove; Grid[p[[{1, 3, 2, 4}]], Alignment -> {Center, Center}]]; styles = {Red, Blue, {Red, Dashed}, {Blue, Dashed}}; pt1 = Plot[{x^2, 2 x^2, 1/x^2, 2/x^2}, {x, 0, 3}, Frame -> True, PlotStyle -> styles, PlotLegends -> LineLegend[...


7

It looks like kglr beat me to it but I was also working on a LegendLayout method, so here it is. styles = {Red, {Red, Dashed}, Blue, {Blue, Dashed}}; pair = (Grid[{Column @ #[[All, 1]], #[[1, 2]]} & /@ Partition[#, 2]] &); Plot[{x^2, 1/x^2, 2 x^2, 2/x^2}, {x, 0, 3}, Frame -> True, PlotStyle -> styles, PlotLegends -> LineLegend[...


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 x^(-0....


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


6

Update 2: Post-processing plots without having to create a new legend: Legended[Show[plots[[;; , 1]], PlotRange -> All], Column[Join @@ plots[[;; , 2, All, 1]], Spacings -> -.8]] Legended[Show[plots[[;; , 1]], PlotRange -> All], Placed[Column[Join @@ plots[[;; , 2, All, 1]], Spacings -> -.8], {Before, Top}]] Original post: Use the (...


6

incRange = 0.020; maxRange = 0.120; BarLegend[{"Rainbow", {0, maxRange}}, Ticks -> Table[i, {i, incRange, maxRange - incRange, incRange}], TickLengths -> 25, RotateTicks -> 180, TicksStyle -> Directive[Opacity[1], White, Dashed, FontColor -> Black], LabelStyle -> {FontSize -> 12}, LegendMarkerSize -> {20, 300}]


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


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


5

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


5

I don't know about PolygonPlotMarkers` package, so I am presenting a general solution. You can always define your own Graphics as markers. For example, I use here regular polygons col = {Red, Blue, Green, Orange, Black}; marker[col_, n_] := Graphics[{col, Polygon[{Cos[2 Pi #/n], Sin[2 Pi #/n]} & /@ Range[n]]} ,...


5

Actually the answer is already given in the documentation for SwatchLegend. All you need to do is to wrap Legended around the Show: Legended[ Show[ plot1, plot2, PlotRange -> All ], SwatchLegend[ {Red, Yellow}, {"A", "B"} ] ] Note: Should the legend become larger and is entered by hand, using Transpose may make this easier, e.g. SwatchLegend @@ ...


4

You defined your function colFun to expect two arguments. It is not clear what you want the result to look like, therefore here are three different possible solutions: ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False, ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False, ImageSize -> 800, PlotLegends -> ...


4

If you look at the box form of your legend (using ToBoxes) you will see that the GraphicsBox representing your marker has the option DefaultBaseStyle -> {"Graphics", {AbsolutePointSize[6]}, Directive[EdgeForm[Directive[Opacity[0.3], GrayLevel[0]]], PointSize[0.5], AbsoluteThickness[1.6], GrayLevel[0]]} Note that it includes an Opacity[0.3] in the ...


4

You can add the LegendMarkerSize option to BarLegend, or simply click on the legend to make it active in the output, then drag a handle to change size. I'd venture something was jiggered in what the default (Automatic) setting of that does between versions.


4

Plot[{Log[x], Log[Sin[x]]}, {x, -1, 23}, PlotLegends -> Placed[LineLegend["Expressions"], {0.8, 0.8}], PlotStyle -> {{Red, Thickness[0.004]}, {Blue, Thickness[0.004]}}, LabelStyle -> {FontSize -> 11}] Or, if you want to frame the legend Plot[{Log[x], Log[Sin[x]]}, {x, -1, 23}, PlotLegends -> Placed[LineLegend["Expressions", ...


4

cp = ContourPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10}, PlotLegends -> BarLegend[Automatic, LegendFunction -> "Panel", LabelStyle -> {FontFamily -> "Monaco", FontSize -> 18, FontColor -> Black}], FrameStyle -> Black, TargetUnits -> "%"] FullForm[cp[[2,1]]] gives the code that constructs the legend. Inspecting that code we find ...



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