Skip to content

Point sizes disagree between matplotlib and datashader #315

Closed

Description

@Sonja-Stockhaus

For plotting points with matplotlib, we use the s argument of scatter(). The square root of s specifies the width and height of the markers in points.

In the datashader approach, we use ds.tf.spread(agg, px=px) to regulate the size of the markers. Here, px is calculated like this: px = int(np.round(np.sqrt(render_params.size))), to make the behavior agree to the matplotlib approach.

Problem: If you alter the dpi in pl.show(), the point size of the datashader points remains the same, whileit changes for matplotlib, leading to different sizes:

dpi=100, mpl=blue, ds=white

blob.pl.render_points(element="blobs_points", size=400, color="blue").pl.render_points(element="blobs_points", size=400, color="white", method="datashader", alpha=1).pl.show(dpi=100)

grafik

dpi=200, mpl=blue, ds=white

blob.pl.render_points(element="blobs_points", size=400, color="blue").pl.render_points(element="blobs_points", size=400, color="white", method="datashader", alpha=1).pl.show(dpi=200)

grafik

dpi=50, ds=blue, mpl=white (note: colors and order swapped!)

blob.pl.render_points(element="blobs_points", size=400, color="blue", method="datashader", alpha=1).pl.render_points(element="blobs_points", size=400, color="white").pl.show(dpi=50)

grafik

Activity

  1. Sonja-Stockhaus commented on Jul 31, 2024

    @Sonja-Stockhaus
    CollaboratorAuthor

    Btw I think for dpi=100, the mpl points are slightly larger than the ds points because marker edges are drawn (default linewidth = 1.5), see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html.
    However, this is not the actual problem

  2. Sonja-Stockhaus commented on Jul 31, 2024

    @Sonja-Stockhaus
    CollaboratorAuthor

    Solution for now: use dpi/100 as a factor to adapt px to varying dpi

  3. linked a pull request that will close this issuedatashader speedup and bugfixes #309on Jul 31, 2024
  4. Sonja-Stockhaus commented on Aug 6, 2024

    @Sonja-Stockhaus
    CollaboratorAuthor

    Now it looks like this, for dpi [50, 100, 200, 300] using blob.pl.render_points(element="blobs_points", size=400, color="blue").pl.render_points(element="blobs_points", size=400, color="yellow", method="datashader", alpha=1).pl.show(dpi=100)
    Should be correct imo

    (matplotlib points bluse, datashader yellow)
    grafik
    grafik
    grafik
    grafik

  5. LucaMarconato commented on Aug 6, 2024

    @LucaMarconato
    Member

    Looks good to me. The tiny pixel offset is probably inevitable and acceptable.

  6. added this to the v0.2.7 milestone on Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions