Tag Info

Hot answers tagged

11

Bob Hanlon's answer works very well, but in some ways it is the hard way of doing things. If you have v9 or v10, then it is arguably easier to use the legend constructs within it. Similar to his answer, we get the image and element names: img = Import["ExampleData/1PPT.pdb", "Rendering" -> "BallAndStick", ImageSize -> 500]; elements = ...


10

bas = Import["ExampleData/1PPT.pdb", "Rendering" -> "BallAndStick", ImageSize -> 500]; elements = Import["ExampleData/1PPT.pdb", "ResidueAtoms"] // Flatten // Union; legend = GraphicsColumn[{ {Graphics[{#[[1]], Disk[{0, 0}, 1]}, ImageSize -> 10], #[[2]]} & /@ Thread[{ ElementData[#, "IconColor"] & /@ elements, ...


8

ListPlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}], PlotLegends ->PointLegend[ (Style[#, 40] & /@ {"sin(x)", "cos(x)"}),Alignment->Center]] Update: As noted by rcollyer in the comments Alignment is an undocumented option for PointLegend. As an alternative, the following old Pane trick works without relying on an undocumented option: ...


8

Taking Rahul's extension of Michael's answer a step further, using MeshShading instead of ColorFunction: data = RandomReal[{0, 3}, 100]; ListLinePlot[data, MeshFunctions -> {#2 &}, Mesh -> {{1, 2}}, MeshShading -> {Blue, Red, Green}, MeshStyle -> None] Update: Although my preferred method is using MeshShading, you can also get a similar ...


7

A small extension of Michael E2's answer to better match how I understand the question: data = RandomReal[{0, 3}, 100]; ListLinePlot[data, ColorFunction -> (Switch[#2, y_ /; y < 1, Blue, y_ /; y < 2, Red, y_ /; y < 3, Green] &), ColorFunctionScaling -> False, MeshFunctions -> {#2 &}, Mesh -> {{0.9, 1.1, 1.9, 2.1}}, ...


6

Still guessing... is the expected output something like the following? ContourPlot[{Re[(u + I v)^2] == 1, Im[(u + I v)^2] == 2, u == 1, v == 2}, {u, -4, 4}, {v, -4, 4}, Axes -> True, Frame -> False, BaseStyle -> Arrowheads[{{.05, .5}}], PlotLegends -> "Expressions", ContourStyle -> ...


6

I find a simple version-independent solution, which produces a very clear output List @@ Plot[x, {x, 0, 1}] // Developer`PackedArrayForm Moreover, it allows a brackets-matching and a multiple-click highlighting!


6

I suspect that ContourPlot doesn't really have a notion of the orientation of curves in a way that will let you preserve them after applying arbitrary transformations. ParametricPlot is probably the way to go. Start with parametric representations of the hyperbolas with the desired orientation: hyperbola1[t_] := {#, -#} &@{Csc[t], -Cot[t]}; ...


6

A reasonable workaround is to use SwatchLegend with LegendMarkers set: ListPlot[ Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}], PlotLegends -> SwatchLegend[{"sin(x)", "cos(x)"}, LabelStyle -> 40, LegendMarkers -> "Bubble" ] ]


5

Here's one way: data = RandomReal[{0, 3}, 100]; ListLinePlot[data, ColorFunction -> (Switch[#2, y_ /; y < 1/3, Blue, y_ /; y < 2/3, Red, y_ /; y < 3/3, Green] &)] Here's a variation: ListLinePlot[data, ColorFunction -> (Switch[#2, y_ /; y < 1, Blue, y_ /; y < 2, Red, y_ /; y < 3, Green] &), ColorFunctionScaling ...


5

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Top] Plot[Sin[x], {x, 0, 2 Pi}, Filling -> 0.5] Plot[Sin[x], {x, 0, 2 Pi}, Filling -> 0.5, FillingStyle -> {Directive[Opacity[0.5], Orange], Directive[Opacity[0.5], Yellow]}, GridLines -> {None, {0.5}}, GridLinesStyle -> Dashed


5

Actually a very simple modification would make your approach work: Plot[Evaluate[u[4., x] /. %], {x, 0, 1}] the problem is that for pattern matching (which is what ReplaceAll (/.) does in the background) 4 (with head Integer) and 4. (with head Real) are two different things. You even might meet cases where using 4. would not be enough to make this work, ...


5

show = {Short@First@#, Last@#} &; Plot[x, {x, 0, 1}] // show


4

You can apply a strategy I learned from @Jens. Add the following to your notebook: Map[SetOptions[#, Prolog -> {{EdgeForm[], Texture[{{{0, 0, 0, 0}}}], Polygon[#, VertexTextureCoordinates -> #] &[{{0, 0}, {1, 0}, {1, 1}}]}}] &, {ParametricPlot}]; Give your plot a name: im1 = PlotU2Treh = ParametricPlot[ ...


4

Perhaps inches = 72; Plot[Sin[x], {x, 0, 4 Pi}, ImageSize -> { 4 inches, Automatic}] If you have to use Quantity you can set the ImageSize converting inches to printer points: ImageSize -> { 72 QuantityMagnitude[Quantity[4, "Inches"]], Automatic} Update: or, better yet, Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle->Thick, ImageSize -> { ...


4

Glad to note this is fixed in 10.0.1.


4

The behavior was corrected in Mathematica 10.0.1. Using the same example: RandomSeed[1] barchart[n_]:= BarChart[RandomInteger[10,{n,3}] ,LabelingFunction->(Placed[#1,Center]&) ,AspectRatio->0.2,ImageSize->700 ,ChartLayout->"Percentile" ] barchart[33] barchart[100] We now have: My tks to ...


4

I can confirm the shift occurs even without the special default styling in your plot (version 9). Your issue stems directly from the use of a special font marker \[FilledSquare] in a PointLegend instead of just using a SwatchLegend. The following does not have the shifting problem. Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, PlotLegends -> ...


3

The ImageSize documentation, under Details reads: "Specifications for both width and height can be any of the following: " d d printer's points (before magnification) 72di di inches (before magnification) So if you want 4 inches you can use: Plot[Sin[x], {x, 0, 4 Pi}, ImageSize -> (72 4)] for other units toPrintPoints = ...


3

As Mr.Wizard indicated, you can also reconstruct the plot using the data. Here is an example: restylePlot2[p_, op : OptionsPattern[ListLinePlot]] := ListLinePlot[Cases[Normal@p, Line[x__] :> x, ∞], op, Options[p]] then we can set the style as we do in plot. For example restylePlot2[myplot2, PlotStyle -> {{Green, Thick, Dashed}, ...


3

data = 14; f1[data_, x_] := x^3 - data x^2 - x + 1 Plot[f1[data, x], {x, -2, 15}, PlotStyle -> Blue, AxesLabel -> {"x", "y"}, Epilog -> {PointSize[Large], Red, Point[{x, 0} /. FindRoot[ f1[data,x], {x, -5000, 5000}]]}] Perhaps better: Plot[f1[data, x], {x, -2, 15}, PlotStyle -> Blue, AxesLabel -> {"x", "y"}, Epilog -> ...


3

Perhaps VertexColors achieves what you're after? Graphics3D[{Thickness[0.005], Line[#, VertexColors -> Hue /@ #]} &@ pts, BoxRatios -> {1, 1, 1}] If you want a "purer" rainbow, perhaps use just the first coordinate of the pts: Graphics3D[{Thickness[0.005], Line[#, VertexColors -> Hue /@ #[[All, 1]]]} &@ pts, BoxRatios -> {1, 1, ...


2

This is not any improvement over rm-rf. In v9 you can also use Legended: Module[{f, col = {Red, Blue}, exp, leg, pm = {\[DiamondSuit], 20}}, f[legend_] := Framed[legend, FrameStyle -> Red, RoundingRadius -> 10, FrameMargins -> 5, Background -> LightBlue]; exp = GraphicsGrid[ Partition[ Table[ListPlot[{Sqrt[Range[0, 50, 5]], ...


2

As I mentioned in a comment, the code works fine the way it is. Here's a faster way: Clear[f]; f[x_] := x; integral = NDSolveValue[{y'[x] == f[x], y[0] == 0}, y, {x, -1, 1}]; Plot[integral[x], {x, -1, 1}]


2

You could use FaceGrids Graphics3D[Cylinder[], Axes -> True, FaceGrids -> {{0, -1, 0}, {-1, 0, 0}}, Boxed -> False]


2

What you observe is simply because you use a multiplication without noticing it. Basic example: "f=" 2 (* 2 "f=" *) If you look at the full form of this output with FullForm[%] you see that it is indeed Times[2, "f="]. Because the terms in a multiplication are re-ordered by Mathematica, you get the wrong result. The solution is to either use Row like ...


2

This seems to do the right thing: VectorPlot[(-efield), {x, -10, 10}, {y, -10, 10}, AspectRatio -> Automatic, VectorScale -> {Automatic, Automatic, 1/#5^2 &}] (although you might want to twiddle the scaling parameter). Notice that the scaling function is a function of five parameters, of which the norm of the gradient is the last, hence #5.


2

I am not sure what you are trying to do exactly, but this works fine: ContourPlot[w[x, y, z] /. z -> int[x, y], {x, 0, 8}, {y, 0, 8}]


2

The simplest approach that I found: choose the center (a0,b0) somewhere in the middle of the plot range and track phase jumps from the center (a0,b0) to any point (a,b) by calculating n points between a0 = 1.5; b0 = 0.; n = 10; phi2[a_, b_] := Fold[# + Mod[#2 - #, 2 π, -π] &, phi[a0, b0], Table[phi[a0 + (a - a0) t/n, b0 + (b - b0) t/n], {t, n}]]; ...


2

You can also do this way: plot = MatrixPlot[RandomReal[{0, 1}, {10, 10}], ColorFunction -> ColorData["GrayTones"], ImageSize -> 200, PlotLegends -> Automatic]; plot /. Rational[x_, y_] :> ScientificForm[N[x/y]] Or combine it with Brett's answer so that it works both for large and small numbers: plot = MatrixPlot[100000000 ...



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