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?

image

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

5 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 :grinning:

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 :slight_smile: )

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.