# Tag Info

14

You can't actually tell the LineLegends construct what the BaseStyle option of the enclosing plot is. But you can set the BaseStyle option for the LineLegend as well. Do not be fooled by the red text when you type BaseStyle inside the LineLegend! This is just another of those cases where things work even though they are not documented and show up in red. ...

12

Even though the documentation for SmoothHistogram doesn't explicitly mention PlotLegends as an option, it is a valid option and works as expected: SmoothHistogram[ Table[RandomVariate[NormalDistribution[c, 1], 500], {c, 0, 3}], PlotLegends -> {"0", "1", "2", "3"}] In general, it's a good idea to try out options that you think should work (for ...

11

As Cormullion pointed out, you will have to create the legend by hand as it would be difficult to have a legend created automatically by GraphicsGrid. However, the simplest method of attaching a legend is to use Legended directly. The structure of Legended when used like this is Legended[ Graph | Graphics | Graphics3D, legend ] Then, in your case, you use ...

10

There is absolutely nothing to stop you setting your legend up this way using a custom plot marker in a SwatchLegend. For example, consider some data: fakedata = Table[FoldList[0.99 #1 + #2 &, 0., RandomVariate[NormalDistribution[0, 1], {99}]], {6}]; Create a custom marker: blob = Graphics[{AbsoluteThickness[1.4], Line[{{-0.5, 0}, {0.5, 0}}], ...

10

Thanks to Nasser M. Abbasi i found a way. To change the Display. The function that you can provide for any ~Legend via LegendFunction wraps the complete ~Legend[] into anything. And he mentioned, that NumberForm encapsulates the numbers. So why not replace them (delayed)? Version 1: Scientific Notation at every Label Hence choosing f[x_] := x /. ...

10

It turns out that the Spacing option does exactly what is needed, even though its use in legend constructs such as PointLegend is not documented, and it shows as red text when you use it in those constructs. PointLegend[{Red, Blue}, {"Series 1", "Series 2"}, LegendMarkers -> {{"\[FilledCircle]", 20}, {"\[FilledCircle]", 20}}, Spacings -> {0.2, ...

10

You can put the SetOptions instruction into your init.m file and then it will always be used. Just evaluate this once and you are all set: (Export[#, Import[#, "Text"] <> "\n\nSetOptions[LineLegend,LabelStyle\[Rule]{FontFamily\[Rule]\"\ Comic Sans MS\",Red}]", "Text", CharacterEncoding :> \$CharacterEncoding]) ...

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 reason for this is that the output in the documentation is rasterized. It is just an image, not the actual object that Plot would produce. Legends are contained in a Legended expression, not in Graphics, which I agree does bring a number of difficulties when using these plots.

8

The answer is to replace "Expressions" with the more controllable LineLegend["Expressions"] as you can pass in options, such as LegendFunction: PlotLegends -> LineLegend["Expressions", LegendFunction -> (Pane[#, ImageSize -> {100, 100}] &)] and for a higher value of t

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

The package PlotLegends is obsolete in v9, and so is the package GraphicsLegend` 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

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

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

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

This first solution is not exactly what you're looking for, but it gets close: BarChart[{{1, 2, 3}, -{4, 5, 6}}, ChartLabels -> {Placed[{"r1", "r2"}, {.5, 2}], Placed[{"c1", "c2", "c2"}, Axis]}] To get the correct representation you need to tweak a bit some values: BarChart[{{1, 2, 3}, -{4, 5, 6}}, ChartLabels -> {Placed[{"r1", "r2"}, ...

6

Best I could do. GraphicsGrid can't read my mind at all... legend = BarLegend[{"LakeColors", {-1, 1}}, LegendLayout -> "Row"]; plots = Table[ DensityPlot[Sin[i x] Sin[y/i], {x, -4, 4}, {y, -3, 3}], {i, 1, 4}]; Column[{ GraphicsGrid[{ {plots[[1]], plots[[2]]}, {plots[[3]], plots[[4]]}}, ImageSize -> 300], legend}, Center]

6

This solution will no longer work in Mathematica 9 because they now use SwatchLegend in FullForm. Instead, apply this: Histogram[{bottom, middle, top}, 10, ChartLayout -> "Stacked", ChartLegends -> {"Bottom", "Middle", "Top"}] /. SwatchLegend[l1_List, l2_List, r1_Rule, r2_Rule] :> SwatchLegend[Reverse[l1, 1], Reverse[l2, 1], r1, r2] The ...

6

This problem often occurs in plotting and graphics because of the use of Foo instead of AbsoluteFoo for the directives. The former uses sizes relative to the plot size, whereas the latter, as the name suggests, uses absolute sizes. In the built-in plot legends in version 9, the plot and the legend are actually two separate objects which are just combined, ...

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

5

I think this does it: Graphics[Legend[{{Graphics[{CapForm[None], Red, Thickness -> 0.05, Line[{{0, 1}, {1, 1}}]}], "A"}, {Graphics[{CapForm[None], Blue, Thickness -> 0.05, Line[{{0, 1}, {1, 1}}]}], "B"}, {Graphics[{CapForm[None], Green, Thickness -> 0.1, Line[{{0, 1}, {1, 1}}]}], "C"}}], ImageSize -> 50] ...

5

Just slide your tick coordinates into position programmatically: ticks = {# - 0.5, #2} & @@@ ticks; Or manually slide them into position using the interactive drawing tools; Quadruple-click the gradient bar in your graphic and then drag: You can copy and paste the edited Graphics or assign it to a symbol.

5

I am going to do this using the Presentations Application. You have a rather special case because you are using even divisions with uneven intervals. Another possibility would be to have two legend scales, one for a larger range and one for close lying values. It is easier to do this with a ContourPlot because the ticks will naturally go with the contour ...

5

I think I found a way to solve the problem. Using a different example: test = Flatten[Table[{i, j, Exp[RandomReal[{0, 10}]]}, {j, 1, 100}, {i, 1, 100}], 1]; min = Log[10, Min[test[[;; , 3]]]]; max = Log[10, Max[test[[;; , 3]]]]; ListContourPlot[test, InterpolationOrder -> 0, Contours -> Flatten[Table[{1., 2., 5.}*10^n, {n, 1, 4}]], ColorFunction ...

5

Here's another solution providing interactive labeling functionality similar to JxB's answer. That is, you can hover over the curves to see their label as a Tooltip, but then click at any point on the curve to make the label stick permanently to that position: Options[burnTooltips] = {ImageSize -> 360, "LabelFunction" -> (Framed[#, FrameStyle ...

5

Here is a demonstration (thanks to Verbeia), using the PlotLegends functionality current in Mma 7. fakedata = Table[FoldList[0.99 #1 + #2 &, 0., RandomReal[NormalDistribution[0, 1], 99]], {6}]; blob = Graphics[{AbsoluteThickness[1.4], Style[Line[{{-0.5, 0}, {0.5, 0}}], Antialiasing -> False], Text["\[FilledCircle]", {-0.25, 0}], ...

5

A little deviation from Verbeia's answer because I don't like the offset of the symbols (e.g. \[FilledCircle]) as PlotMarkers. I am using Disk and Circle primitives instead. mydisk[col_] := Graphics[{col, Disk[{0, 0}, 1]}]; mycirc[col_] := Graphics[{col, Circle[{0, 0}, 1]}]; ListLinePlot[fakedata, PlotStyle -> {Orange, Blue, Green}, PlotMarkers ...

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