Tag Info

Hot answers tagged

18

maybe this will provide a little insight: first look at the evaluation points used by ContourPlot: f[x_?NumericQ, y_?NumericQ] := (Sow[{x, y}]; Sin[3.2 x]*Sin[1.3*y] - 2.1*Sin[1.3*x]*Sin[3.2*y]); {plot, dat} = Reap[ContourPlot[f[x, y] == 0, {x, 0, 2}, {y, 0, 2}, PlotPoints -> 50, ContourStyle -> Red]]; Row[{ ...


10

A simple modification of the answer in the linked Q/A: data = RandomReal[{0, 3}, 100]; ListLinePlot[data, MeshFunctions -> {#2 &}, Mesh -> {{1, 2}}, MeshShading -> {Blue, Directive[Red, Dashed], Green}, MeshStyle -> None] Use MeshShading -> {Dashing[.02], Dashing[None], Dotted} to get


9

A simple example of the problem can be generated with: Plot[x^0.5, {x, 30, 120}, Frame -> True] Here we have a vertical line at 40. If we plot this without the frame: Plot[x^0.5, {x, 30, 120}, Frame -> False] We see that this actually corresponds to the axes that Mathematica generates. AxesOrigin /. Options@Plot[x^0.5, {x, 30, 120}] ...


8

MandelbrotSetPlot does produce a normal plot. "Normal" here means that the result has Head Graphics. Recommended reading on the term "head": Everything is an expression. Show can be used to combine expressions which have the head Graphics. The line below has two problems: Show[MandelbrotSetPlot[{-2.5 - 2.5 I, 2.5 + 2.5 I}], Point[0, 0]] Point[0,0] is ...


8

I recently revisited this, and found that RegionPlot3D is by far the fastest way to plot orbitals, compared to Image3D and ContourPlot3D. I was surprised by the difference, so I thought it's worth posting this. In addition, I also made the process of choosing the plot parameters automatic, based on simple estimates for the size of the orbital wave ...


8

Off[Solve::ztest]; var = {R, r, a, p, s}; assume = Join[ Thread[var > 0], {R > r, Element[n, Integers], n > 2}]; eqns = { R == s*Csc[Pi/n]/2, r == s*Cot[Pi/n]/2, a == n*s^2*Cot[Pi/n]/4, p == n*s}; sol = Reverse[Assuming[assume, Simplify[Solve[ Join[eqns, assume], #, Reals][[1]] & /@ Select[ ...


8

You may use NMinimize[] on the results of ParametricNDSolve[] like this: g = 9.81; m = 10; rho = 1.225; Cd = 0.5; A = 0.1; rcd = rho Cd A; vMax = 40; EndTime[theta_] := (2 vMax Sin[theta])/g + 5; sol[Ux_, Uy_, Uz_] := Quiet@ParametricNDSolve[{ m z''[t] == -m g - Tanh[z'[t]] 1/2 rcd (z'[t] - Uz)^2, z[0] == 0, z'[0] == v Cos[theta], m ...


7

This should give you a head-start: With[{r = 0.025, x1 = 1.5, thick = 0.002}, Graphics[{ (* gray field *) LightGray, Disk[{x1, 0}, 1, {-Pi/2, Pi/2}], Disk[{-x1, 0}, 1, {Pi/2, 3 Pi/2}], Rectangle[{-x1, -1}, {x1, 1}], Black, Thickness[thick], Line[{{{-x1, 1}, {x1, 1}}, {{-x1, -1}, {x1, -1}}}], Circle[{x1, 0}, 1, {-Pi/2, Pi/2}], ...


7

points = Table[{x, .5 x^2 - 3 + RandomReal[]}, {x, -3, 3}]; Show[{ListPlot[points, PlotLegends -> {"Experiment"}], Plot[{.5 x^2 - 3}, {x, -3, 3}, PlotStyle -> Red, PlotLegends -> {"Model"}]}]


7

I believe the first part of your question is answered by Stack. Observe: g := Stack[] something[f1[g], f3[g]] something[f1[{something, f1}], f3[{something, f3}]] So you can find that g was evaluated in f1 or f3 and further that these were evaluated in something. However this should not be necessary for your Ticks application. The value of Ticks ...


6

The option VectorPoints determines how many vector boxes there are. The plot domain is subdivided into a grid, whose grid points span the plot domain in each direction. Equal-size rectangular boxes surround each grid point so that the boxes are adjacent and tile the plot range (ignoring any padding). Here is a picture with VectorPoints -> 9 (the ...


5

NIntegrate[f[t], {t, -1, x}] integrates the same thing over and over again, when a point is needed by Plot. Integrate what you need one time only: f[x_] = Which[-1 <= x <= 0, x, 0 <= x, x^2, True, 0]; ϕ[x_] = NDSolve[{Derivative[1][g][t] == f[t], g[-1] == 0}, g, {t, -1.5, 1}][[1, 1, 2]][x]; Plot[ϕ[x], {x, -1.5, 1}]


5

It appears that you are using MeshFunctions -> {Abs[#2] &} to cause the curve to change color when it crosses +1.5 and -1.5, but it does not. This is because, although a line segment of data may cross one of those values, the corresponding line segment of Abs[data] does not necessarily do so. For clarity, consider data modified by two additional ...


5

It appears that PlotRange must be specified to assure that the Full range of data is displayed in the second DensityPlot. Also, specifying PlotPoints improves the appearance of the first DensityPlot. DensityPlot[Max[0, 0.1 - Abs[1. - Sqrt[x^2 + y^2]]], {x, -1.1, 1.1}, {y, -1.1, 1.1}, ColorFunction -> (Opacity[#, Blue] &), PlotPoints -> 100, ...


5

I am not sure I understand your question fully. Does this do what you are looking for? ParametricPlot3D[{u Cos[t], u Sin[t], 1.2 u}, {t, 0, 2 Pi}, {u, 1, 1.5}, Mesh -> Full, MaxRecursion -> 0, PlotPoints -> {25, 5}] It will not draw arcs, just straight lines between mesh points. The mesg corresponds to the sampled points precisely (thanks ...


5

You can also use RegionPlot3D: RegionPlot3D[ reg = (2 x^3 + y^2 + z^2 - 1)^3 - (1/10) x^2 z^3 - y^2 z^3 <= 0 && x >= 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, Boxed -> False, Axes -> None, PlotPoints -> 40, PlotStyle -> Red, Background -> Black] Implicit regions could be refined but is not as pleasing ...


5

I don't know why it looks like that. However: It looks like you are trying to restrict the plot region and you do this by defining the function to return Null in other areas. This is not the usual way to do it. Use RegionFunction instead. Plot3D[10*q, {q, 0, 1}, {L, 0, 5}, BoxRatios -> 1, Mesh -> None, AxesLabel -> {"q", "L", "Price"}, ...


5

Something like: Plot[-2 Cos[Sqrt[50]/2 Sin[theta]] - 2, {theta, 0, Pi/2}, PlotStyle -> Thick, ColorFunction -> (Opacity[Sin@#, Blue] &), AxesLabel -> {\[Theta], E[\[Theta]]}] You can also make the line color vary with theta while opacity varies with Sin@theta: Plot[-2 Cos[Sqrt[50]/2 Sin[theta]] - 2, {theta, 0, Pi/2}, PlotStyle -> ...


5

Unless you specify the tick mark length in your tick specifications tick marks are rendered with default length and style. tickF = {#, DateString[#, {"MonthNameShort", " ", "Day", "/", "YearShort"}]} & /@ AbsoluteTime /@ DateRange[##, {10, "Day"}] &; Example data: data = {{3368649600, 8}, {3369427200, 10}, {3370291200, 12}, {3370636800, ...


4

For the tick labels you can use Table[{i, 1 + i}, {i, 1, Length[a]}], and to add a line and text you can use Epilog: MatrixPlot[{a}, ColorRules -> {1 -> Red, 2 -> Blue, 3 -> Green, 4 -> Gray}, Frame -> True, Mesh -> True, MeshStyle -> Black, FrameTicks -> {{None, None}, {Table[{i, 1 + i}, {i, 1, Length[a]}], None}}, ...


4

Or is a logical function giving True or False as an answer. Perhaps, what you mean is curves for both x^2 + y^2 == 1 and x^2 + y^2 == 1/4, in which case you should use (as suggested in a Comment by Nasser) ContourPlot[{x^2 + y^2 == 1, x^2 + y^2 == 1/4}, {x, -1, 1}, {y, -1, 1}]


4

f[x_, y_] := x + y g[x_, y_] := Exp[x y] - y; ParametricPlot[{y, f[x, y]}, {x, -5, 5}, {y, -5, 5}, MeshFunctions -> {Function[{a, b, x, y}, g[x, y]]}, Mesh -> {{0}}, PlotStyle -> None, BoundaryStyle -> None, MeshStyle -> {{Opacity[1], Thick, Black}}, PlotRange -> All, Frame -> False]


4

When Automatic fails the same thing can, luckily, be done manually: rules = {1 -> Red, 2 -> Blue, 3 -> Green, 4 -> Gray, 5 -> Yellow, 6 -> Orange}; a = RandomInteger[{1, 6}, {50}]; MatrixPlot[ {a}, ColorRules -> rules, PlotLegends -> SwatchLegend[rules[[All, 2]], rules[[All, 1]]] ] A horizontal version (this is an update in ...


4

lgp1 = LayeredGraphPlot[gph, Right, VertexLabeling -> True, DirectedEdges -> False, SelfLoopStyle -> False, PlotRangePadding -> 0, AspectRatio -> 1, ImageSize -> 400]; Post-process lgp1 to add the appropriate alignment point ({Right, Center} for the root vertex and {Left, Center} for the leaves) to the Text primitives representing the ...


4

Update: Using the memoization trick suggested by @george2079 in the comments combined with MeshFunctions we get the same picture in 0.015625 seconds: fa[a_?NumericQ, b_?NumericQ] := fa[a, b] = NIntegrate[a*x + b, {x, 0, 1}]; First@Timing[ContourPlot[fa[a, b], {a, 0, 10}, {b, 0, 10}, Contours -> {}, ContourShading -> None, MeshFunctions -> ...


4

I agree NDSolve is the way to go, but I think I know why there has been a slow down since V5. I believe sometime since V5 symbolic preprocessing was introduced, which can cause overhead. We can turn this off in V10 and see a drastic speed up: f[x_] := Which[-1 <= x <= 0, x, 0 <= x, x^2, True, 0] ϕ[x_] := NIntegrate[f[t], {t, -1, x}] Plot[ϕ[x], ...


4

Straight mesh lines can be obtaining by specifying corresponding plot points with zero max recursion. Then points can be drawn with post-processing (/. ... :> ...) n1 = 10; n2 = 3; ParametricPlot3D[{u Cos[t], u Sin[t], 1.2 u}, {t, 0, 2 Pi}, {u, 1.0, 1.5}, Mesh -> {n1, n2}, PlotPoints -> {n1 + 2, n2 + 2}, MaxRecursion -> 0, NormalsFunction ...


4

Using Graph instead of GraphPlot you get many convenient options for styling as shown in @ubpdqn's answer. If you have to use GraphPlot: You can use the option PlotStyle->Black to get black edges. To style the vertices you can post-process the output to change Text primitives into graphics primitives of your choice. For example: el={1 -> 2, 2 ...


4

I will abuse the fact you want to plot points in specific positions, not get those coordinates: If you know how to transpose ragged array it is quite strightforward: ListPlot[Flatten[data, {2}], PlotStyle -> Blue] as pointed out in comments, it is not general so here's something useful: data = {{1, 2, 3, 4}, {5, 6}, {}, {1, 5}, {2, 4, 7}}; Join @@ ...


4

Your function seems to produce values with small imaginary components, which Plot deliberately ignores. If you Chop your results, the function seems to plot just fine: m = {{(1 + 1/k)/x^2, 1/k}, {-1/k, x^2 (1 - 1/k)}}; {{l1, l2}, {v1, v2}} = Eigensystem[m]; g = Solve[{0, 1} == a v1 + b v2, {a, b}]; alpha = First[a /. g]; beta = First[b /. g]; d[x_, h_, n_] ...



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