Tag Info

Hot answers tagged

10

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


9

The expression that is plotted in the legend are the provided pure functions (with some scoped internal variable names). PlotLegends is somewhat confused so we have to provide explicit entries for the Legend. Since the desired result is somewhat unclear here a few suggestions: v[x_, k_] := k*x^-k; g[x_, k_] := (x^-k)*Sin[x^k]/(1 + x^k); f[x_, k_] := x^k/(1 ...


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

The package PlotLegends` is obsolete in v9, and so is the package Graphics`Legend` that the Mie code notebook was using. Since you are running v9, you might as well use the new stuff which is integrated much better. Of course, as there are several plots to combine, the method is going to look similar, but not as convoluted as the old form. The high level ...


8

You also aren't getting the right line thickness in your legend. I'd suggest a slightly different route, of creating custom legend markers, similar to the method described in this answer, and including them in a SwatchLegend. legmarkers = MapThread[Graphics[{#1, AbsoluteThickness[2], Line[{{-1, 0}, {1, 0}}], #2}] &, {col, {Disk[{0, 0}, 0.3], ...


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


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

After Amatya's edit MeshMarker[a_, b_, col_: Lighter@Blue] :=RegionPlot[True, {x, -2, 2}, {y, -2, 2}, Frame -> False, PlotStyle -> col, Mesh -> {a, b}, ImageSize -> 20] SwatchLegend[{1, 2}, {"Continuation Region", "ExitRegion"}, LegendMarkerSize -> {{30,30}}, LegendMarkers -> MeshMarker @@@ {{2, 2, Yellow}, {0,0}}] Before Amatya's ...


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


6

I'm sure you can move from here and make the legend you desire. (*Make your plot*) plot = ListContourPlot[ Table[Cos[Sqrt[bx^2 + by^2]], {bx, -1, 1, 0.1}, {by, -1, 1, 0.1}], ContourLabels -> All, ColorFunction -> "LakeColors"]; (*Specify your legend labels*) labels = Range[0.1, 1, 0.1]; (*Make legend*) legend = ...


6

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


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

The plots are misaligned because plot b doesn't have the exact same options as a, which causes it to be drawn slightly different. If you give the same options to plot b (PlotRange, AxesOrigin, and AxesLabel) b = Plot[-2 f'[z], {z, 0, 5}, PlotLegend -> "Theory", PlotRange -> {{0, 5}, {0, 1}}, LegendPosition -> {1.1, -0.4}, AxesOrigin -> {0, ...


5

You could add in a label function: label[k_, x_] := Graphics@Text["k = " <> ToString[k], {uh[x, a, go, s, m, k], x}, {0, -1}]; Then show it all together: Show[Table[{plt[k], label[k, 1]}, {k, 1.0, 3.5, 0.5}]]


5

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


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


4

I find it easier to put this type of legend together by hand, as follows: Legended[ Show[ (* fill in with plots without PlotLegends option *) ], LineLegend[{ColorData[1][1], Red}, {"asd", "asd"}, Joined -> {True, False}] ] The disadvantage is you lose the automatic color generation, but you gain control and it is automatically formatted as you ...


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

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

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


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


3

The SciDraw package (LevelScheme successor) has support for labelling curves. Here's an example: Needs["SciDraw`"] Figure[ FigurePanel[ { FigLine[Plot[Sin[x], {x, 0, 10}], LineColor -> Apricot, CenterLabel -> "sine", CenterLabelPosition -> 0.55, TextOffset -> Top]; FigLine[Plot[Cos[x], {x, 0, 10}], LineColor -> ...


3

http://reference.wolfram.com/mathematica/ref/Files/BarLegend.en/I_70.gif The code in the link as well as documentation of BarLegend may be helpful in customising bar legend. Look at Contours option. I was overly optimistic, however, ListDensityPlot[ Table[ArcTan[Cos[x + y], Sin[x + y]], {x, 0, 10, 0.01}, {y, 0, 1.2, 0.01}], DataRange -> {{0, 10}, ...


3

Of course, this got a lot easier in version 9: BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], ChartLegends -> Placed[SwatchLegend[{Orange}, {"Estimate"}], Bottom]]



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