Skip to main content

plotting - Animating a growing ListPlot


I stumbled upon this (rather contrived but interesting) integer sequence. As it exhibits quite different behaviour at different scales, I would like to generate an animated ListPlot of it, where I'm changing the domain and range at an exponential rate to zoom through the orders of magnitude.


I've got something working but it's pretty glitchy and I'm having trouble getting the size of the points to shrink at a good proportional rate.


seq[n_] := seq@n = Module[{b = 2, l},
While[! IntegerQ[l = Sqrt@Length@IntegerDigits[n, b]], ++b];
Flatten[Transpose@(IntegerDigits[n, b]~Partition~l)]~FromDigits~b
]

plot[n_] :=
ListPlot[
seq /@ Range[n],
PlotRange -> {{0, n + 1}, {0, n + 1}},
AspectRatio -> 1,
ImageSize -> 400,
PlotStyle -> PointSize[0.2/n]
]
frames = Rasterize[#, "Image"] & /@ Table[plot[10^(n/25)], {n, 25, 100}];
ListAnimate[frames]


or ultimately


Export["sequence.gif", frames]

which gives


enter image description here


As you can see, despite the fixed aspect ratio and the fixed image size, the actual frames seem to have different sizes, leading to artefacts at the bottom. The axes are glitching all over the place as well, probably due to the changing tick labels.


Ideally I also want to increase the maximum n by another one or two orders of magnitude. I've also considered making the lower bound grow as well (so that I'm always showing a fixed ratio between nMax and nMin, since the interesting features of the plot are concentrated around the seq[n]==n line).


How could I improve the animation to get rid of the glitches, get a consistently useful PointSize and just generally make it look smoother?





Edit: I've incorporated some of the great suggestions in the comments. Here is my current version of the plot function, this time with fixed PointSize to show the issue of the increasing density. I've also adapted the code to only plot one order of magnitude at a time, because lower-left 10th of the domain isn't really interesting at any given scale:


plot[n_] := 
ListPlot[
{#, seq@#} & /@ Range[Round[n/10], Round@n],
PlotRange -> {{n/10 - 1, n + 1}, {n/10 - 1, n + 1}},
AspectRatio -> 1,
ImageSize -> 400,
PlotStyle -> PointSize[0.01],
ImagePadding -> {{10, 10}, {10, 10}},
TicksStyle -> Directive[FontOpacity -> 0, FontSize -> 0]

]

And this is the corresponding animation:


enter image description here


However, that still has issues with the point size and the efficiency of the solution. As I said, I'd like to continue up to one or two more orders of magnitude, and the problem only gets worse, of course.


I also wonder if it would be possible to generate the full ListPlot only once (probably without any axes at all) and then generate an animation of a growing window into that ListPlot. I feel like that should be significantly faster to process, especially if I want to increase the framerate. Of course, that wouldn't make the PointSize issue any easier.




Comments

Popular posts from this blog

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1....