## plotting – Plot solution to damped driven pendulum in \$(-pi,pi)\$

I’m solving the damped driven pendulum:

``````{γ, g, ω} = {0.5, 1.5, 2/3};
{X0, V0} = {0.6184, 0.};
tmax = 1000;
sol = NDSolve({x''(t) + γ x'(t) + Sin(x(t)) == g Cos(ω t), x(0) == X0, x'(0) == V0}, x, {t, 0, tmax}, MaxSteps -> Infinity)
sol1(t_) := x(t) /. sol((1))
sol2(t_) := x'(t) /. sol((1))
``````

I then want to plot the solution $$(x,x’)$$ constraining $$x$$ to the interval $$(-pi,pi)$$. I came with modulo to make one part $$(-2pi,0)$$, the other $$(0,2pi)$$, and then restrict the range to $$(-pi,pi)$$. First, it is inelegant. Second, I end with a gap in the middle that even with a big number of `PlotPoints` I cannot get rid of.

``````ParametricPlot({{Mod(sol1(t), -2 π), sol2(t)}, {Mod(sol1(t), 2 π), sol2(t)}}, {t, 0, tmax},
Frame -> True, Axes -> False, PlotStyle -> Black, PlotRange -> {{-π, π}, {-3, 3}}, PlotPoints -> 500)
`````` Using an alternative formulation for modulo:

``````normalize(angle_?(NumericQ(#) && Im(#) == 0 &)) := angle - 2 Pi Floor((angle + Pi)/(2 Pi))
``````

to plot

``````ParametricPlot({normalize@sol1(t), sol2(t)}, {t, 0, tmax},
Frame -> True, Axes -> False, PlotStyle -> Black, PlotRange -> {{-π, π}, {-3, 3}}, PlotPoints -> 500)
``````

I get redundant horizontal lines: How to make such plot elegantly?

Posted on

## plotting – Plot part of a contour curve of the imaginary part of a complex function

Use `RegionFunction`

``````Clear("Global`*")

f(z_) := ((z + 1/z)^2 - 4)*(1 - I)

Legended(
Show(
ComplexContourPlot(Im(f(z)) == 0, {z, 2},
ContourStyle -> Red,
RegionFunction -> Function({z, func}, 0 < Re(f(z))),
PlotPoints -> 75),
ComplexContourPlot(Im(f(z)) == 0, {z, 2},
ContourStyle -> Blue,
RegionFunction -> Function({z, func}, Re(f(z)) <= 0),
PlotPoints -> 75)),
Placed(LineLegend({Red, Blue},
{"Re(f(z))>0", "Re(f(z))≤0"}), {.7, .8}))
`````` Posted on

## plotting – Mathematica More Detailed Plot Around Asymptotes

I’m wanting to export some animations from Mathematica involving animating certain plots with asymptotes. At certain points in time, one of the parameters approaches a value where the function no longer has an asymptote. So it gets really steep. Take the following example:

``````g1[x_, t_] := Tan[x]*Sin[2 Pi t] + Cot[x]*Cos[2 Pi t];
myplot [t_] :=
Plot[g1[x, t], {x, -1.5 [Pi], 1.5 [Pi]},
PlotRange -> {{-1.5 [Pi], 1.5 [Pi]}, {-1.5 [Pi], 1.5 [Pi]}},
Axes -> False, AspectRatio -> Automatic,
PlotStyle -> Thickness[0.01]];

myplot[0.25/720]
myplot[0.5/720]
myplot[1/720]
myplot[2/720]
``````

Notice how, for the first plots, near the asymptote, the function is not plotted all the way to the edge of the graph; it gets cut off:

View post on imgur.com

This is because when the argument is near zero, the tangent part of the function is disappearing; when it is exactly at zero, that tangent goes away. Basically, I think the function is becoming so steep there, Mathematica is failing to plot it.

For an animation, this is extremely undesirable since it causes flickering. I understand why the veritcal lines would disappear exactly at zero, since the Tan[x] part goes away completely. That’s why, in my animation, I add a small offset to t, say 1/900, so it never reaches zero exactly. But even when I’m around zero, I still get the problem where the steep part of the function disappears.

Basically, how can I tell Mathematica to plot the function where it is extremely steep, all the way to the edge of the graph?

Posted on

## plotting – Make a nice panel figure, with a 3D plot

There are some solutions on how to make nice panel figures, for example, or the SciDraw package. By nice, I mean reasonably presentable – without miles of space in between figures, and plots within the panel have consistent sizes and fonts, and the labels are inline from plot to plot. I’m not asking for much.

However, I wantinclude a panel figure which has a 3D plot in it. I’m finding it very difficult with the padding in `GraphicsGrid`. For example,

``````plot1 = Plot3D[Sin[x/100 + y^2], {x, -300, 300}, {y, -2, 2},
ColorFunction -> "RedBlueTones", Boxed -> False ,
LabelStyle -> {FontSize -> 13, FontFamily -> "Helvetica", Black},
AxesLabel -> {"x axis label", "y axis label", "z value", " "},
PlotLabel -> "3D Map",
ViewPoint -> {1.9660038626106877, 2.036484683486844,
1.8540655182930692},
ViewVertical -> {-0.38056099743618316, -0.39420402835939466,
0.836526455801371}];

plot2 = DensityPlot[Sin[x/100 + y^2], {x, -300, 300}, {y, -2, 2},
PlotRange -> All, PlotPoints -> 200,
ColorFunction -> "RedBlueTones", PlotLabel -> "Density Plot",
FrameLabel -> {{"x axis label", " "}, {"y axis label", " "}},
LabelStyle -> {FontSize -> 13, FontFamily -> "Helvetica", Black}];

plot3 = Plot[{Sin[x/100 + 0]}, {x, -300, 300}, PlotRange -> All,
Frame -> True, FrameLabel -> {"y axis label", " z label"},
AspectRatio -> 1,
LabelStyle -> {FontSize -> 13, FontFamily -> "Helvetica", Black},
PlotLabel -> "x axis cut"];
plot4 = Plot[{Sin[0 + y]}, {y, -2, 2}, PlotRange -> All,
Frame -> True, FrameLabel -> {"x axis label", " z label"},
AspectRatio -> 1,
LabelStyle -> {FontSize -> 13, FontFamily -> "Helvetica", Black},
PlotLabel -> "y axis cut"];

GraphicsGrid[{{plot1, plot2}, {plot3, plot4}},
ImageSize -> {1000, 1000}]
``````

You can see the output, each plot is a different size, with massive gaps between the figures. I’ve played about with padding on `GraphicsGrid`, but that hasn’t been very helpful. The titles are at different heights. It doesn’t look great. Any suggestions on improvements? ## plotting – Mathematica returns an empty plot for the real part of the eigenvalues

I have a 3*3 matrix. Using Mathematica I have found the eigenvalues in terms of “K”. The problem arises when I’m plotting the real part of eigenvalues against “k” (k is a positive number ranging from 0.02 to 0.05). Can someone guide me, why I’m getting empty? ``````(*Here is my Matrix*)

J1 = {{-v^2 - w^2 - F - D1*k^2, -2*u*v, -2*u*w}, {v^2,
2*u*v - (F + k1) - D2*k^2, 0}, {w^2, 0,
2*u*w - (F + k2) - D3*k^2}};

(*I have defined the eigen values as the function of the following
parameters*)
{λ4(F_, D1_, D2_, D3_, k1_, k2_, u_, v_,
w_), λ5(F_, D1_, D2_, D3_, k1_, k2_, u_, v_,
w_), λ6(F_, D1_, D2_, D3_, k1_, k2_, u_, v_, w_)} =
Eigenvalues(J1);

(*Here are the numerical values of the parameters*)
{λ4(0.025,
290, 61.443, 11, 0.0043, 0.046, 0.381, 0.0767, 0.186), λ5(
0.025, 290, 61.443, 11, 0.0043, 0.046, 0.381, 0.0767,
0.186), λ6(0.025, 290, 61.443, 11, 0.0043, 0.046, 0.381,
0.0767, 0.186)};

(*Plotting the real part of the eigen values against k*)
Plot({Re(λ1), Re(λ2), Re(λ3)}, {k, 0.01, 0.05},
PlotStyle -> {{Thick, Red}, {Thick, Blue}}, Frame -> True,
FrameLabel -> {Style("k", 18), Style("Re(λ)", 18)})
``````

Posted on

## Plot count of rows by hour, each date separately, from non-standard datetime values, in Google Sheets

Choose Insert > New sheet and enter this formula in cell A1:

``````=arrayformula(
query(
{
query(
if(
len(Input!A1:A),
{
text(datevalue(left(Input!A1:A, 10)), "yyyy-mm-dd"),
hour(timevalue(regexreplace(Input!A1:A, "(d+) (d+)\$", "\$1:\$2")))
},
iferror(1/0)
),
"select Col1, Col2, count(Col2)
where '" & text(B1, "yyyy-mm-dd") & "' <= Col1
and Col1 <= '" & text(B2, "yyyy-mm-dd") & "'
group by Col1, Col2
label count(Col2) '' ",
0
);
{ iferror(sequence(24)/0, "baseline"), sequence(24), iferror(sequence(24)/0, 0) }
},
"select Col2, sum(Col3)
group by Col2
pivot Col1
label Col2 'Hour' ",
0
)
)
``````

Then create a chart based on the result table.

Posted on

## How to plot the subplots of dataframe?

Lets Say I have data frame of describe() . What Describe dataframe does , it shows the 25% , 50% , mean etc. I have 33 columns Now If I want to plot the subplots for better visualization . How could it be done?

## Plot the Total Drag Fd Hi. I’m trying to do part b. The min drag that I have is 0.006U^2+1.5833(W^2/U^2).

Posted on Tags , ,

## plotting – My Plot is empty when I run code

``````ee = 0.5;
g = 0.1;
gs = Sqrt(g);
f = (Sin(gs*x))^2;
low = gs*Pi/2 ;
up = -low ;
ode = { y''(x) + (2ee - f/g)*y(x) == 0 , y(low)==0 , y(up)==0 }
sol = NDSolve(ode, y(x), {x, low , up})
Plot(y(x) /. sol, {x, low, up})
``````

Boundary conditions are y(low)=y(up)=0. But when I plot this, it shows an empty plot.

## how to plot the amplitude and phase spectrum of Fourier Transform of periodic function Abs[Sin[t]] and corresponding non-periodic piecewise function

the two function

``````x(t_) := Piecewise({{Sin(t) , 0 <= t <= Pi}}) # will get frequency function X(w)
xhat(t_) := RealAbs(Sin(t)) # will get fourier coeff ck
``````

I want to show the amplitude-frequency relations graph plotted as in Fig.D.2 between periodic function `xhat(t_)` and corresponding non-periodic function `x(t_)` Amplitude and Phase of a Periodic Signal (Fourier Series)

how to plot the amplitude and phase spectrum of a Fourier Transform in this specific pattern?

similar answers does not work for me.

Posted on