Closed
Description
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()
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