scattermore icon indicating copy to clipboard operation
scattermore copied to clipboard

How to add points to existing plot with scattermoreplot?

Open scienception opened this issue 2 years ago • 4 comments

I created a plot with scattermoreplot, and want to add additional points in every for loop iteration. Is there such functionality such as adding points() to a plot() plot?

scienception avatar Oct 24 '23 03:10 scienception

Hi, yes there is. There are a few ways to do that:

  • if you want to see the intermediate results, you can use the plain scattermore() function to plot into a bitmap and then add the bitmap to the output using e.g. R function rasterImage or so.
  • if you just need to assemble multiple pieces of input together that aren't available at the same time, you may use scatter_points_rgbwt to rasterize the point set into an intermediate format (see https://exaexa.github.io/scattermore/reference/scatter_points_rgbwt.html), merge multiple rasters using merge_rgbwt (https://exaexa.github.io/scattermore/reference/merge_rgbwt.html) and in the end convert the whole thing to a plottable bitmap using these 2 things: https://exaexa.github.io/scattermore/reference/rgbwt_to_rgba_int.html and https://exaexa.github.io/scattermore/reference/rgba_int_to_raster.html

The best way probably depends on your use-case -- what are (roughly) the point amounts that you want to add in each iteration?

exaexa avatar Oct 24 '23 07:10 exaexa

PS I just realized we also have a vignette that contains some relevant code -- the merging of the intermediate layers is described roughly around here: https://exaexa.github.io/scattermore/articles/low_level_interface.html#merging-rgbwt-and-rgba-layers

exaexa avatar Oct 24 '23 07:10 exaexa

Thank you! Is it possible to pass a vector for pointsize in geom_scattermost(count_pairs_matrix, pointsize=2)? I need the points to have variable size (depending on some count). Basically I want the size of the point to increment with how many observations for that (x,y) point I got.

scienception avatar Oct 24 '23 12:10 scienception

no, unfortunately not, the API is made for single-pixel operations only (for speed) and you are supposed to expand the points after that. (The logic there is that for actual big data, expanding single pixels is much faster than plotting lots if large points.)

The options are:

  • You can use the same trick as above to plot a few layers of points with different sizes.
  • You might want to use the histogram functionality instead, and then expand and colorize the histogrammed points with a palette of just 2 colors. (See https://exaexa.github.io/scattermore/articles/low_level_interface.html#coloring-densities ).

As a quick question, how many points (roughly) are you plotting in total? Scattermore is specialized for amounts where point sizes typically do not matter anymore; which is exactly why doing "precise" stuff like this gets complex.

Cf. this issue: https://github.com/exaexa/scattermore/issues/18

exaexa avatar Oct 24 '23 12:10 exaexa