Hot answers tagged

11

There appears to be a bug, not in Integrate or in BesselK, but in the vertical-axis Ticks of LogLogPlot. Consider the simple case, LogLogPlot[Exp[x], {x, 10^-10, 1}, PlotRange -> All] as it should be. However, LogLogPlot[Exp[x], {x, 10^-10, 1}, WorkingPrecision -> 50, PlotRange -> All] In fact, any value of WorkingPrecision except ...


11

region = ImplicitRegion[ 0 < z < 4 - x*y && 0 <= x <= 2 && 0 <= y <= 1, {x, y, z}]; RegionPlot3D[region, BoxRatios -> {1, 1, 1}, Axes -> True] Volume[region] (* 7 *) RegionMeasure[region] (* 7 *) Integrate[1, {x, 0, 2}, {y, 0, 1}, {z, 0, 4 - x*y}] (* 7 *) Integrate[1, Element[{x, y, z}, ...


9

First use Tally to count the number and then use BubbleChart. data1 = Tally[data] /. {{x_, y_}, z_} :> {x, y, z} BubbleChart[data1]


8

working with Texture: Wig[n_, x_, y_] := (1/Pi) Exp[-(x^2 + y^2)] (-1)^n LaguerreL[n, 2 (x^2 + y^2)]; mx[n_, x_] := Sqrt[2/Pi] (1/(n! 2^n))*Exp[-2 x^2] HermiteH[n, Sqrt[2] x]^2; my[n_, y_] := Sqrt[2/Pi] (1/(n! 2^n))*Exp[-2 y^2] HermiteH[n, Sqrt[2] y]^2; p2d = Plot[mx[3, x], {x, -3.5, 3.5}]; range = {{-3.5, 3.5}, {-3.5, 3.5}, {-1/2, 1/2}}; poly = { ...


7

You can use Part (also written [[...]]) to get what you want. For example, myList= Table[{i, i}, {i, 1, 20}]; ListPlot[myList] ListPlot[myList[[1;;-1;;2]]] (* every second point *) ListPlot[myList[[1;;-1;;3]]] (* every 3rd point*)


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


5

I think this is a bug due to the creation of an improper SparseArray for the Raster of the ArrayPlot. ap = ArrayPlot[{{0}}, ColorFunction -> Function[a, RGBColor[a, a, a]], ColorFunctionScaling -> False]; {sa} = Cases[ap, _SparseArray, Infinity] The normal expression Normal[sa] {{0.}} looks OK, but InputForm[sa] ...


5

DynamicModule[{n = 20}, Column[{Row[{Slider[Dynamic[n], {1, 100, 1}], Dynamic[n]}], Dynamic[Legended[PieChart[Thread[Style[#[[All, 2]], #[[All, 1]] /. {True -> Red, False -> Green}] ], ChartStyle -> {Green, Red}] &@ Tally@RandomChoice[{True, False}, n], SwatchLegend[{Green, Red}, {False, True}]]]}]] ...


5

ParametricPlot3D[{{x, y, Wig[3, x, y]}, {x, Pi, Rescale[y, {-Pi, Pi}, {0, 1}] mx[3, x]}, {-Pi, y, Rescale[x, {-Pi, Pi}, {0, 1}] mx[3, y]}}, {x, -Pi, Pi}, {y, -Pi, Pi}, Mesh -> None, PlotRange -> All, BoxRatios -> 1, PlotStyle -> {LightBlue, Directive[EdgeForm[], Red], Directive[EdgeForm[], Green]}]


5

zmax = 20; r = 1 Animate[Show[Graphics3D[Cone[{{0, 0, 0}, {0, 0, 2}}, r]], Graphics3D[{PointSize[.05], Point[{1.1 r (zmax - v)/zmax Sin[v], 1.1 r (zmax - v)/zmax Cos[v], 2 v/zmax}]}], ParametricPlot3D[{r (zmax - z)/zmax Sin[z], r (zmax - z)/zmax Cos[z], 2 z/zmax}, {z, 0, zmax}, PlotStyle -> {Thick, Blue}], Axes -> True, PlotRange -> ...


5

Apart from using texture, you can also convert the 2D plot to 3D plot directly. For example, p1 = Plot3D[Wig[3, x, y], {x, -3.5, 3.5}, {y, -3.5, 3.5}, PlotRange -> All]; p2 = Plot[mx[3, x], {x, -3.5, 3.5}]; p3 = Graphics3D @@ (FullGraphics[p2] /. Line[pts__] :> Line[pts /. {x_, y_} :> {x, -3.5, y}]); Show[p1,p3]


4

As requested, posting my comment as an answer. The Table takes {alpha1, {0.1, 0.15, 0.2}} to iterate alpha1 over the list S1[t_, alpha_, n_] := Sin[100 alpha t]; Plot[Evaluate@Table[S1[t, alpha1, 2], {alpha1, {0.1, 0.15, 0.2}}], {t, 0, 2}, PlotLegends -> LineLegend[Table[alpha1, {alpha1, {0.1, 0.15, 0.2}}], LegendLabel -> alpha1]]


4

The Red/Green problem stems from the fact that Tally returns tallied values in the order each element is first encountered, and the other issue is because Tally doesn't return a 0 entry for elements not in the list. Both issues can be solved with a custom tally: explicitTally[list_,toTally_List] := {#, Count[list, #]} & /@ toTally; If you use ...


4

In recent versions PlotTheme -> "Monochrome" may suit your needs: Plot[{Sin[t], Sin[2 t], Sin[3 t]}, {t, 0, 2 π}, PlotLegends -> {"t=1", "t=2", "t=3"}, PlotTheme -> "Monochrome"] dat = Table[{Sin[t], Sin[2 t], Sin[3 t]}, {t, 0, 2 π, 0.1}]\[Transpose]; ListLinePlot[dat, PlotLegends -> {"t=1", "t=2", "t=3"}, PlotTheme -> "Monochrome"] ...


4

The ways listed work perfectly well, but you can save yourself a couple of keystrokes just by doing myList[[;;;;2]] If you don't provide starting and ending points for the first ;;, Mathematica is kind enough to assume that you want to go from the beginning (1) to the end (-1). For my tastes, at least, this looks a little nicer too. (It'll auto-format ...


4

Just for fun: data = Tally @ raw Note: raw is your original data Graphics[{{PointSize @ Abs[#[[2]]/50], Tooltip[Point @ #[[1]], #[[1]]]} & /@ data}, Axes -> True] Output:


3

Inspection of the InputForm of the generated plot reveals that a function is used to generate the labeling rectangles: DisplayFunction :> (FormBox[ FrameBox[ StyleBox[ StyleBox[ PaneBox[#1, Alignment -> Left, AppearanceElements -> None, ImageSizeAction -> "ResizeToFit"], LineIndent -> 0, StripOnInput ...


3

You can use PlotMarker in ListPlot to do that data = Table[ Table[{t, f[t]}, {t, 0, 2 π, π/10}], {f, {Sin[#] &, Sin[2 #] &, Sin[3 #] &}}]; ListPlot[data, Joined -> True, PlotLegends -> {"t=1", "t=2", "t=3"}, PlotMarkers -> Automatic] Or something like ListLinePlot[data, PlotLegends -> {"t=1", "t=2", "t=3"}, ...


3

Show[ListContourPlot[#, Contours -> {0}, ContourShading -> None, ContourStyle -> Directive[Thick, #2]] & @@@ {{list1, Red}, {list2, Green}}]


3

If I understand your question correctly, here is a possible approach to extracting the {x, y} list of values corresponding to the zeroes of your function when the function is only available through data points. First of all, I will generate a data list, since you did not provide one. Let's consider for instance the following function as an example: f[x_, ...


3

w = w0 (1 + z^2/zR^2); w1 = 100 200*^-6; w0set = 2*^-6; λ0 = 632*^-9; Ixy2 = FullSimplify[ComplexExpand[(.5 Exp[I (k x + Δϕ)] + .5 Exp[I l ArcTan[y, x]])*Conjugate[.5 Exp[I (k x + Δϕ)] + .5 Exp[I l ArcTan[y, x]]]]]; Grating0 = Ixy2 /. {k -> 11 2 π/λ 0/8, w0 -> w0set, zR -> π w0set^2/λ0, z -> 10*^-4, p -> 0, l -> 0, r -> Norm[{x, y}], Δϕ ...


3

The reason why the contour is broken is because ContourPlot seems to be based on the Intermediate Value Theorem and it will fail to find points where the function just touches zero. The details have been discussed in the post Problem with ContourPlot. For your question, you can first factor out x and y, then the contour will be fine: P[x_, y_] := ...


3

If you use a number instead of Automatic for the AspectRatio option, it seems to work: ContourPlot[Sin[x y], {x, 0, 3 Pi}, {y, 0, Pi}, Contours -> 5, PlotLegends -> Placed[BarLegend[Automatic], Right], AspectRatio -> 1/2, ImageSize -> 200] Since AspectRatio->Automatic simply determines the ratio by the plot range, one can make an easy ...


3

One way is to add a text element in the graphics object: Manipulate[ Show[Plot[ Piecewise[{{ξ x^2, x <= 1/(2 ξ - 1)}, {x, x > 1/(2 ξ - 1)}}], {x, 0, 5}], Graphics[{Line[{{1/(2 ξ - 1), 0}, {1/(2 ξ - 1), 25}}], Text["label", {1/(2 ξ - 1), 0}]}]], {ξ, 0, 1, Appearance -> "Labeled"}]


3

Sometimes, you may not want to reconstruct the legend from scratch then you can extract the legends from the plots, and make adjustments on them, for example p=Show[plots, PlotRange -> All]; opt = First@Cases[plots[[1]], LineLegend[x_List, y_List, opt__] :> {opt}, ∞]; lgd = LineLegend[ Sequence @@ Transpose[ First@Cases[#, ...


3

The option LegendMargins can be used to significantly reduce the spacing. This option can be added directly to LineLegend plots = Table[ Plot[x i, {x, 0, 1}, PlotStyle -> {Hue[i/11]}, PlotLegends -> LineLegend[{"Serial " <> ToString[i]}, LabelStyle -> {FontFamily -> "Times", 10}, LegendMargins -> {0, 0}], ...


3

g1 = Graph[{Dog -> Apple, Apple -> Screwdriver}, VertexLabels -> "Name", GraphLayout -> "CircularEmbedding", ImagePadding -> 40] g2 = GraphComplement[UndirectedGraph[g1], VertexLabels -> "Name", ImagePadding -> 40, VertexCoordinates -> GraphEmbedding[g1]] Using GraphPlot GraphPlot[AdjacencyMatrix[g2], ...


3

As a quick and dirty answer: time = Table[t/60, {t, 1, 2726}] // N; x = Get@"http://pastebin.com/raw/7xwgGDsd"; (* make these data TemporalData *) td = TemporalData[Transpose[{time, #}] & /@ Transpose[x]]; $PlotTheme = "Scientific"; Show[ { ListLinePlot @ td, ListLinePlot[ MovingMap[ Mean, td, Quantity[180, "Events"] ], ...


3

If you want to stick with one call to ListPlot and all of your data have the same time limits, something like this might work. ListPlot[Flatten[{Transpose[x], MovingAverage[#, 180] & /@ Transpose[x]}, {2, 1}], DataRange -> {0, 46}, Joined -> True, Frame -> True, FrameLabel -> {{"x (m)", ""}, {"t (sec)", ""}}, ImageSize -> Large] ...


2

This is not entirely the same, as it changes coloring and z-scaling, but perhaps something similar may be of help. Essentially, the zero values are lifted by a small increment, while the original z-range is preserved. data = {{1, 1, 1, 1}, {1, 0, 3, 1}, {2, 0, 0, 1}}; ListPlot3D[data /. x_ /; x < .01 -> 0.01, Mesh -> None, InterpolationOrder ...



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