Tag Info

Hot answers tagged

11

If you have your own color function, then passing an explicit BarLegend to PlotLegends seems to be the only way out. This also means that you'll have to feed the min/max for your data, but this isn't hard. Here's an example: With[{cf = Blend[{Blue, White, Red}, #] &, data = Table[Sin[x y], {y, 0, 3, 0.1}, {x, 0, 3, 0.1}]}, ListPlot3D[data, ...


11

Two work-arounds: (1) Use TickLabels BarLegend[{"Rainbow", {-0.015, 0.015}}, ImageSize->300, Charting`TickLabels -> (Style[NumberForm[#, {Infinity, 3}],Bold,Black,12] & /@ Range[-.015, .015, .005])] (2) Use LabelingFunction: BarLegend[{"Rainbow", {-0.015, 0.015}}, ImageSize->300, LabelingFunction -> (Style[NumberForm[#, ...


9

(This answer has just the circles, not the box with color scale information) To get circular looking disks I use Offset[r] for the radius, which ignores aspect-ratio and plot scale: Plot[x, {x, 0, 30}, AspectRatio -> 1/10, Epilog -> { {Red, Circle[{5, 5}, 5]}, {Green, Circle[{20, 20}, Offset[10]]} }] When putting Graphics together with ...


8

Instead of simply using Red as the directive, set the face and edge colors explicitly so that there is no ambiguity. If you use FaceForm@Red and EdgeForm@Red (or None) in your definitions for redDisk and redRectangle, you get legend markers without black borders.


8

Not the prettiest, perhaps, but I just wanted to finish what I started. I was able to finish it after having read ssch excellent answer and see how he used Offset. This plot was truly a challenge to me, and the problem is in combining the different graphics. Had I tried this again I would probably do everything with Graphics and not use ListLinePlot at all. ...


8

`AbsoluteThickne is another useful approach:e.g. op = Table[AbsoluteThickness[2], {3}]; leg = LineLegend[Automatic, {"Max", "Mea", "Min"}]; ListLinePlot[{historyobjetivomejor, historyobjetivomedia, historyobjetivopeor}, AxesLabel -> {"Generacion", "Objetivo"}, PlotStyle -> op, PlotLegends -> leg] Varying thickness: using: Manipulate[ ...


8

After a rather long debugging session in our chat we could determine the reason of the problem and come up with a workaround. In short, we first tried whether the issue appears for the most basic Graphics[], which it didn't. As it turned out the gray background is introduced by using PlotLegends as in the example above. We went further by comparing ...


7

You might consider using Grid in place of GraphicsGrid. Doing so comes with both pluses and minuses, so it is not a no-brain choice. However, Grid will accommodate any shape and size of display object automatically. When putting plots in a grid, I find it is usually best to set ImageSize in the plot explicitly. Using your example plot at Medium size plot = ...


7

Plot[{Sin[x], Cos[x]}, {x, 0, 5}, PlotStyle -> {Blue, Red}, PlotLegends -> Placed[Framed@LineLegend[{Blue, Red}, {"L1", "L2"}, LegendLayout -> "Row"], Below]]


7

I consider myself an amateur. I was also interested in this question, and I found the following code solves the problem. However, the command that solves the problem ("Ticks") shows up highlighted in red. You can change many of the features of the legend, like size, add a label, etc. Legended[ ListDensityPlot[Table[ArcTan[Cos[x + y], Sin[x + y]], {x, ...


7

If you look into the source code ClearAttributes[BarLegend, ReadProtected] ?? BarLegend And into nested functions (BarLegend,Charting`iBarLegend $\to$ Legending`LegendDump`iColorBandLegend $\to$ Legending`LegendDump`parseColorBand) you can find the following code Switch[Legending`LegendDump`colorfunction, _String, ...


7

You can do : LogLinearPlot[{Log[x], x Sin[x], x Cos[x]}, {x, 1, 100}, PlotLegends -> Placed[{"Log(x)", None, "x Cos(x)"}, After]]


6

The main problem is that the aspect ratio of the plot and its container are different. You can still use GraphicsGrid with the correct settings: plot = Plot[{Sin[x], Cos[x]}, {x, 0, 10}, Frame -> True, PlotLegends -> Placed[LineLegend["Expressions"], {.5, 0.5}], Background -> Green, AspectRatio -> 1/GoldenRatio]; GraphicsGrid[{{plot, ...


6

As it often happens, when I was researching for writing a fine question I also digged through the documentation and found the answer. There is an option LegendMarkerkSize which in my opinion has an unintuitive name in the case of the BarLegend. Anyway it is exactly meant to do what I needed: testPlot = ArrayPlot[ Array[RandomInteger[100] &, {100, ...


5

Needs["PlotLegends`"]; Manipulate[ ShowLegend[ plTest, {ColorData["Rainbow"][1 - #1] &, 10, ToString[Round[LMax, 0.01]], ToString[Round[LMin, 0.01]], LegendPosition -> {0.6, 0}, BaseStyle -> {FontSize -> n} } ], {{n, 12, "how big?"}, 4, 16, 1,Appearance -> "Labeled"}, ContinuousAction -> False, Initialization ...


5

First, I'm not certain if your plot is correct. Notice that ListDensityPlot arranges successive rows of the array up the page, and successive columns across. The first iterator in the table creates the rows and the second iterator creates the columns. So if you want the normal x and y axis you have to reverse the iterators. On the other hand, DataRange ...


5

I wonder whether you would be content with a simpler SwatchLegend: ListDensityPlot[ Table[{2 Pi Sin[x], 2 Pi Cos[x]}, {x, 0, 2 Pi}], ColorFunction -> "BlueGreenYellow", ImageSize -> 500, PlotLegends -> SwatchLegend[ Table[ Blend[{Blue, Green, Yellow}, Rescale[x, {0, 2 Pi}]], {x, 0, 2 Pi, Pi/8}], Range[0, 2 Pi, Pi/8], ...


5

Plot[Sin[x], {x, 0, 1}, PlotLegends -> Placed[BarLegend[{ColorData["TemperatureMap"][1 - #] &, {15, 30}}, LegendMarkerSize -> 300, LegendLabel -> "T(\[Degree]C)", Ticks -> Table[{i, 45 - i}, {i, 15, 31}], LabelStyle -> {Bold, Black, 11}], {Top, Center}]]


5

A few minor errors corrected (mostly extra commas): MakeExponent[x_Integer] := "\*SuperscriptBox[10," <> ToString[x] <> "]" tick = {10^#, MakeExponent[#]} & /@ Range[-10, 10, 1]; A = {1/#, #^2} & /@ Range[100]; B = {1/#, #^1.5 - 1} & /@ Range[100]; A1 = {1/#, #^2} & /@ Range[100]; B1 = {1/#, #^1.5 - 1} & /@ Range[100]; ...


5

The style for labels in a legend is determined by the option LabelStyle. To get the legend markers to match the style of the plot without rescaling, one approach is to use AbsoluteDashing and AbsoluteThickness to style the plot lines. With[{d = AbsoluteDashing[8], t = AbsoluteThickness[4]}, Plot[{E^(4 x), E^(3 x), E^(2 x), E^x, E^(x/2), E^(x/3), E^(x/4)}, ...


5

Adapting an example in the docs you could do it this way: table[pairs_] := Grid[pairs, BaseStyle -> {TextAlignment -> Left}, Alignment -> {Left, Automatic}] Then use LegendLayout -> table, to give you: Edit To reverse it just use Reverse: reversetable[pairs_] := Grid[Reverse@pairs, BaseStyle -> {TextAlignment -> Left}, ...


4

I think the "easiest" way is to abandon the use of LevelScheme to position your legend. Instead, I would do something like this, legend = myplot /. Legended[_, Placed[l_, ___]|{Placed[l_, ___]}] :> l; Legended[ Figure[ (* fill in details *), Placed[ legend, placement ] ]


4

Specifying FrameTicks adds a "legend" to MatrixPlot's row: legend = {"Hello", "How are you?", "Good Bye"}; MatrixPlot[{{1, 2, 1}, {3, 0, 1}, {0, 0, -1}}, FrameTicks -> { {True (* Left *), Thread[{Range@Length@legend, legend}](* Right *)}, {True (* Bottom *), False (* Top *)}}]


4

The reason the OP's hack works is because Inset allows to place non-graphic objects in a graphics object. The reason it does not work is because Inset places the inset in the center of hosting graph by default. The package has a command to include non-graphics objects: ScaledLabel. The following function takes a legend plot pand returns the command to ...


4

If you want legends, you may want to try the code I posted under Creating legends for plots with multiple lines?. To use it, copy all the definitions in the first code block of that answer, then re-create your plot this way: z[r_, t_] = {r^2 Cos[2 t] - 2 r Sin[t], 2 r Cos[t] + r^2 Sin[2 t]}; zz[t_] = Table[z[r, t], {r, 0.1, 4, 0.5}]; p = ...


4

I don't know if there's an elegant way. The colors are embedded in the plots, and changing them after the fact takes some work. I basically do what the OP alluded to, but as postprocessing. Collect the colors in the graph and remap them according to some color function. plots = Table[ Plot[Evaluate[Table[Sin[(4(3-j)-i)x], {i, 4-j}]], {x, 0, 2 Pi}], ...


4

You can define a layout function as shown in the documentation :- colors = {Red, Magenta, Pink, Orange, Yellow, Green, Darker[Green], Cyan, Blue, Purple, Black, Gray}; names = Table["Color " <> ToString[i], {i, 1, Length[colors]}]; table[pairs_] := TableForm[pairs, TableAlignments -> Left, TableSpacing -> {2, 1}]; LineLegend[colors[[;; ...


4

The fastest way is to use TextCell only there you can have full control over the text: lbl = TextCell["fox jumped over two lines that I want to\nalign to the left", TextAlignment -> Left]; So: Plot[Sin[x], {x, 1, 12}, ImageSize -> 500, Frame -> True, Axes -> False, PlotLegends -> {Placed[SwatchLegend[{Red}, {lbl}, ...


4

I don't recall a direct way of doing this with normal legending, but you can accomplish same with something like: ListLinePlot[{historyobjetivomejor, historyobjetivomedia, historyobjetivopeor}, PlotStyle -> {Thickness[0.008]}, AxesLabel -> {"Generacion", "Objetivo"}, LabelStyle -> {24, Bold}, ImageSize -> Large, PlotLegends -> ...


4

A work-around: wrap the BarChart with Legended Legended[BarChart[{{12, 14, 16, 18}, {8, 10, 11, 12}, {2, 5, 6, 7}, {1, 3, 5, 7}}, ChartStyle -> {Green, Blue, Red, Orange}, ImageSize -> 500], MapThread[Placed[PointLegend[{#1}, {#2}, LegendMarkers -> {#3}, LegendMarkerSize -> 20, ...



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