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


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

Below is an extended comment showing the effects that can happen when one ignores the correlations among parameter estimators (either on purpose or because journal authors or editors don't know enough about statistics to include necessary information). First I create some data with the same curve form as the function CDDHybrid and a set of predictor values ...


6

Here you go, sphereplot = With[ {z = 1/2 Cos[8 ϕ], r = 1}, Show[ Graphics3D@Sphere[], ParametricPlot3D[{Cos[ϕ] Sqrt[r^2 - z^2], Sin[ϕ] Sqrt[r^2 - z^2], z}, {ϕ, 0, 2 π}], Boxed -> False ] ]; Now you just need a function that will place the animation point at a given angle around the curve, ball[ϕ_] := With[ {z = 1/2 ...


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

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

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]


5

Introduction The first thing that I noticed is that the functional form for all of your CDD and LHS functions are identical. I propose that rather than defining six functions for each, we define one function and change the input arguments to cover the various cases. cdd[s_, a_, b_, c_] := 10^(a + b*c - b*s)*Exp[-10^(s - c)] lhs[s_?NumericQ, a_?NumericQ, ...


5

table = Table[Sin[j^2 + i], {i, 0, Pi, 0.1}, {j, 0, Pi, 0.1}]; Show[ListPlot3D[table], ListPlot3D[table, Filling -> 0, RegionFunction -> (#3 <= 0 &), FillingStyle -> Blue]]


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

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

Use the (afaik) undocumented option "Spacings" for LineLegend: legend = LineLegend[Hue[#/11] & /@ Range[10], ("Serial " <> ToString[#]) & /@ Range[10], LabelStyle -> {FontFamily -> "Times", 10}, "Spacings" -> {1, .2}] or use LegendLayout with a custom layout function: legend = LineLegend[Hue[#/11] & /@ Range[10], ...


4

Could use Filling -> {4 -> {{1}, LightRed}, 1 -> {{3}, LightBlue}, 3 -> {{6}, LightRed}} and omit FillingStyle. Or Filling -> {1 -> {3}, 4 -> {6}}, FillingStyle -> {{LightBlue, Opacity[0.5]}, {LightRed, Opacity[0.5]}} which respectively produce the plots below.


4

ClearAll[f] f[p_, a_] := {Cos[a Sin[p #1]] Cos[#1], Cos[a Sin[p #1]] Sin[#1], -Sin[a Sin[p #1]]} &; sphere = Graphics3D[{Opacity[0.7], Sphere[]}]; Dynamic[Show[sphere, ParametricPlot3D[f[10, .25][u], {u, 0, 2 Pi]}, Mesh -> {{{Clock[{0, 2 Pi}], {Red, PointSize[.05]}}}}, MeshFunctions -> {#4 &}], Boxed -> False] /. Point[x_] :> ...


4

Here's how to make all the color schemes in ColorBrewer available in Mathematica: ColorBrewer = Association /@ Association[Import["http://colorbrewer2.org/export/colorbrewer.json"] /. {s_String /; StringMatchQ[s, NumberString] :> FromDigits[s], s_String /; StringMatchQ[s, "rgb(*)"] :> Interpreter["Color"][s]} /. v_ /; VectorQ[v, ...


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

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


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 ColorFunction for SphericalPlot3D takes 6 arguments, referring to the Cartesian and spherical coordinates. cf = ColorData["Rainbow"]; plot = SphericalPlot3D[ 1/((Sin[θ]^4* Cos[ϕ]^4*0.049896792) + (2*(Sin[θ]* Cos[ϕ])^2*(Sin[θ]* Sin[ϕ])^2*(-0.01555592)) + (2*(Sin[θ]* Cos[ϕ])^2*(Cos[θ])^2*(-0.030833372)) + ...


3

With[{path = CoordinateTransform[ "Spherical" -> "Cartesian", {1, (Sin[5 fi] .5 + Pi/2), fi} ]} , Show[ ParametricPlot3D[path, {fi, -Pi, Pi}], Graphics3D[{Sphere[], AbsolutePointSize @ 12, Dynamic[Point[1.01 path /. fi -> Clock[2 Pi, 3]], UpdateInterval -> .05]}], PlotRange -> 1.5] ]


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

This is expected behavior since the values are all rescaled to lie between 0 and 1 prior to feeding them to the ColorFunction. So there will always be some portion of the plotted region that corresponds to a value of 0 and a region that corresponds to a value of 1. Look at this simplified example, DensityPlot[2 + UnitStep[x], {x, -3, 3}, {y, -3, 3}, ...


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

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


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

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


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



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