# Is there a simpler way to plot less points?

**URL:** <https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786>\
**Category:** General Usage\
**Tags:** question, plotting, plots, recipe\
**Created:** [February 4, 2022, 11:04am UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786 "2022-02-04T11:04:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred\_He](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred_he/32/14298_2.png) [@Fred\_He](https://discourse.julialang.org/u/Fred_He)\
**Post date:** [February 4, 2022, 11:04am UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/1 "2022-02-04T11:04:11Z")

</div>

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](https://global.discourse-cdn.com/julialang/original/3X/5/4/54f9ae7a479f1cf2556c1e0832ca33486253c79f.png)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 4, 2022, 11:09am UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/2 "2022-02-04T11:09:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [February 4, 2022, 11:12am UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/3 "2022-02-04T11:12:07Z")

</div>

You didn’t post your plot call so hopefully this makes sense

You can give a stride using a `@view`

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

```

---

<div class="post-metadata">

**Author:** ![Fred\_He](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred_he/32/14298_2.png) [@Fred\_He](https://discourse.julialang.org/u/Fred_He)\
**Post date:** [February 4, 2022, 11:37am UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/4 "2022-02-04T11:37:26Z")

</div>

Yes this can work and it’s what I’ve been doing… But I was wondering if there’s any keywords to do it…

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 4, 2022, 1:07pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/5 "2022-02-04T13:07:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 4, 2022, 1:27pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/6 "2022-02-04T13:27:15Z")

</div>

> [@lmiq](#):
>
> You can use for example `x[begin:2:end]` to sample every 2 points

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](https://plasma-gate.weizmann.ac.il/Grace/) 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.)

---

<div class="post-metadata">

**Author:** ![Fred\_He](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred_he/32/14298_2.png) [@Fred\_He](https://discourse.julialang.org/u/Fred_He)\
**Post date:** [February 4, 2022, 2:57pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/7 "2022-02-04T14:57:45Z")

</div>

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 😀

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [February 4, 2022, 2:58pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/8 "2022-02-04T14:58:59Z")

</div>

> [@lawless-m](#):
>
> `scatter(x=(@view xs[1:1000:end])`

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?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 4, 2022, 3:05pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/9 "2022-02-04T15:05:52Z")

</div>

> [@joa-quim](#):
>
> won’t know what a Julia view is and hence the real sub-sampled arrays must be created

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

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 4, 2022, 3:11pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/10 "2022-02-04T15:11:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [February 4, 2022, 3:12pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/11 "2022-02-04T15:12:17Z")

</div>

> [@lmiq](#):
>
> one could only pass the pointer to the beginning of the view of the array to the low level function, without copying.

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

---

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [February 4, 2022, 4:43pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/12 "2022-02-04T16:43:43Z")

</div>

I have never used the InspectDR backend for plots but it’s “[F1-acceleration](https://github.com/ma-laforge/InspectDR.jl#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.

---

<div class="post-metadata">

**Author:** ![Ickaser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ickaser/32/28852_2.png) [@Ickaser](https://discourse.julialang.org/u/Ickaser)\
**Post date:** [July 3, 2024, 1:29pm UTC](https://discourse.julialang.org/t/is-there-a-simpler-way-to-plot-less-points/75786/13 "2024-07-03T13:29:25Z")

</div>

There is an example of how to accomplish this using a Plots recipe [here](https://github.com/JuliaPlots/Plots.jl/issues/2523), if that helps the next person with this question.
