Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point sizes disagree between matplotlib and datashader #315

Open
Sonja-Stockhaus opened this issue Jul 31, 2024 · 4 comments · May be fixed by #309
Open

Point sizes disagree between matplotlib and datashader #315

Sonja-Stockhaus opened this issue Jul 31, 2024 · 4 comments · May be fixed by #309
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Sonja-Stockhaus
Copy link
Collaborator

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

@Sonja-Stockhaus Sonja-Stockhaus added the bug Something isn't working label Jul 31, 2024
@Sonja-Stockhaus Sonja-Stockhaus self-assigned this Jul 31, 2024
@Sonja-Stockhaus
Copy link
Collaborator Author

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

@Sonja-Stockhaus
Copy link
Collaborator Author

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

@Sonja-Stockhaus Sonja-Stockhaus linked a pull request Jul 31, 2024 that will close this issue
@Sonja-Stockhaus
Copy link
Collaborator Author

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

@LucaMarconato
Copy link
Member

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

@timtreis timtreis added this to the v0.2.7 milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants