Skip to content

[Bug]: Dots could not align to center when overlap dots with the same coordinates #24636

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

Closed
zqfang opened this issue Dec 6, 2022 · 3 comments

Comments

@zqfang
Copy link

zqfang commented Dec 6, 2022

Bug summary

When edgecolors is not None in ax.scatter, overlapped dots could not align to the center even if dots with the same coordinates

Code for reproduction

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'Gene_set': ['2022', '2022', '2022', '2022', '2022', '2021', '2021', '2021', '2021', '2021'], 
                                  'Term': ['regulation of cation channel activity (GO:2001257)', 
                                                'establishment of mitochondrion localization, microtubule-mediated (GO:0034643)', 
                                                'DNA-templated transcription, termination (GO:0006353)', 
                                                'mitochondrion transport along microtubule (GO:0047497)',
                                                 'mitochondrial fission (GO:0000266)', 'regulation of cation channel activity (GO:2001257)', 
                                                'establishment of mitochondrion localization, microtubule-mediated (GO:0034643)', 
                                                'DNA-templated transcription, termination (GO:0006353)', 
                                                'mitochondrion transport along microtubule (GO:0047497)', 
                                                'mitochondrial fission (GO:0000266)'], 
                                  'area': [82.83045070066913, 625.0, 66.30612244897958, 260.94674556213016, 177.7777777777778, 82.83045070066913, 625.0, 66.30612244897958, 260.94674556213016, 177.7777777777778], 
                                  'p_inv': [2.5549417930429006, 0.7132534017074245, 0.6939727070003071, 0.6939727070003071, 0.6489820335167326, 2.5549417930429006, 0.7132534017074245, 0.6939727070003071, 0.6939727070003071, 0.6489820335167326]})

## scatters
fig, (ax1, ax2) = plt.subplots(2,1, figsize=(4,8))
smax = df["area"].max()
x = "Gene_set"
y = "Term"
blk_sc1 = ax1.scatter( x=x, y=y, s=smax * 1.2, edgecolors="none", c="black", data=df, marker='o', zorder=0)
wht_sc1 = ax1.scatter( x=x, y=y, s=smax * 1.0, edgecolors="none", c="white", data=df, marker='o', zorder=1)
sc2 = ax1.scatter(x=x, y=y, data=df, s="area", edgecolors="none", c="p_inv", cmap=plt.cm.RdBu, marker="o", zorder=2)
ax1.set_title("set edgecolors='none', scatter aligned at center", fontsize=16)
ax1.margins(x = 0.25, y = 0.1)

## when set edgecolors, could not align at center
blk_sc2 = ax2.scatter( x=x, y=y, s=smax * 1.2, edgecolors="gray", c="white", data=df, marker='o', zorder=0)
sc2 = ax2.scatter(x=x, y=y, data=df, s="area", edgecolors="none", c="p_inv", cmap=plt.cm.RdBu, marker="o", zorder=2)
ax2.set_title("set edgecolors='gray', scatter not aligned at center", fontsize=16)
ax2.margins(x = 0.25, y = 0.1) 
plt.show()

image

Actual outcome

The actual outcome is the ax2 mentioned above

Expected outcome

The expected outcome should be is the ax1 which mentioned above

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.5.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10

Jupyter version

No response

Installation

conda

@tacaswell
Copy link
Member

This is like due to the draw-as-marker fast-path with does pixel snapping. [sorry for the very terse answer]

@zqfang
Copy link
Author

zqfang commented Dec 6, 2022

@tacaswell , however, the default behavior is not intuitive to a non-expert user like me.

@anntzer
Copy link
Contributor

anntzer commented Dec 7, 2022

This is essentially the same as #7233 afaict, feel free to comment on that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants