# Is there a simpler way to plot less points?

I have a solution for PDE with a lot of points. Is there any keyword in Plots.jl that can directly easily plot fewer points? If not, maybe we can manage to add one?

You can use for example `x[begin:2:end]` to sample every 2 points

You didnâ€™t post your plot call so hopefully this makes sense

You can give a stride using a `@view`

``````xs = rand(10_000);
ys = rand(10_000)
scatter(x=(@view xs[1:1000:end]), y=(@view ys[1:1000:end]))
``````

Yes this can work and itâ€™s what Iâ€™ve been doingâ€¦ But I was wondering if thereâ€™s any keywords to do itâ€¦

DifferentialEquations has a `Plots.jl` recipe that accepts plot argument: `plotdensity`.
I reckon you could create a similar type recipe to plot your own PDE solutions.

1 Like

One nice feature would be to be able to control the spacing of marker symbols (circles, squares, etcetera) independently from the density of the data (used to plot the lines). This is useful if you are using the markers only as labels, not to indicate data, and want to have sparse markers with smooth curves.

You can achieve this if you first plot the full data as a line, and then plot subsampled data as markers. But that makes setting up a legend difficult because the plotting software thinks you have two separate curves. Itâ€™s also inconvenient if you have unequally spaced data but want equally spaced markers.

Many years ago (2004, whew), I contributed a patch to Grace 6 to add a â€śminimum symbol separationâ€ť feature precisely for these reasons; itâ€™s pretty trivial to implement at the low level. (It looks like Grace development halted, sadly â€¦ Grace 6 is still only available as a â€ś5.99â€ť beta.)

3 Likes

Thatâ€™s exactly what I think! I even thought about sampling the points based on gradientâ€¦
It would be great if Plots.jl has the same featgure

Do we really gain anything in using views? At the end the data must be sent to the low level plotting lib that wonâ€™t know what a Julia view is and hence the real sub-sampled arrays must be created. Or Iâ€™m I wrong?

1 Like

That is not necessarily true, since one could only pass the pointer to the beginning of the view of the array to the low level function, without copying. But I donâ€™t believe that any performance benefit can be perceived there in the middle of all the plotting stuff. Also, a view of a discontinuous memory block (which is the case here) may harm performance (I think that may be true, although the example Iâ€™d put was not showing that )

you make one less copy, though, I think Plots.jl would make a copy anyway, but this way youâ€™re only copying once instead of twice

That is when the view points to a contiguous block of memory, not when it jumps one-every-nth other point.

2 Likes

I have never used the InspectDR backend for plots but itâ€™s â€śF1-accelerationâ€ť has always sounded like a very useful feature that I wished could be added to plotting more broadly. I donâ€™t know if that is implemented in the underlying library, or if it is in Julia and could be extracted to use in other plotting routines.