astrofrog / mpl-scatter-density

:zap: Fast scatter density plots for Matplotlib :zap:
BSD 2-Clause "Simplified" License
497 stars 25 forks source link

cross glitch on subplot #41

Open elvis1020 opened 5 months ago

elvis1020 commented 5 months ago

Hello. I love this scatter density implementation that resembles topcat (from astronomer to astronomer =]). I came across this cross forming as a glitch, and it changes color/location depending on the zoom/pan, and randomly disappear. CM_selection

below is the code that I used:

f1, ax1 = plt.subplots(1, 2, figsize=[5.8, 3.1], subplot_kw=dict(projection='scatter_density'), sharex=True, sharey=True)
ax1 = ax1.flatten()
norm = ImageNormalize(vmin=0., vmax=1000, stretch=LogStretch())

polyconf = dict(fc=None, ec='k', fill=False, ls='--')
ax1[0].scatter_density(apo_sel['bp_rp'], apo_sel['absmag'], cmap=colormapsT['all'], norm=norm)
ax1[0].scatter_density(apo_sel.loc[apo_sel['filter']]['bp_rp'], apo_sel.loc[apo_sel['filter']]['absmag'],
                      cmap=colormapsT['green'], norm=norm)
ax1[0].scatter_density(apo_sel.loc[apo_sel['cm_mainsequence']]['bp_rp'], apo_sel.loc[apo_sel['cm_mainsequence']]['absmag'],
                      cmap=colormapsT['blue'], norm=norm)
ax1[0].scatter_density(apo_sel.loc[apo_sel['cm_giants']]['bp_rp'], apo_sel.loc[apo_sel['cm_giants']]['absmag'],
                      cmap=colormapsT['red'], norm=norm)
ax1[0].add_patch(mpatches.Polygon(cm_giants_cut, **polyconf))
ax1[0].add_patch(mpatches.Polygon(cm_mainseq_cut, **polyconf))
ax1[0].text(0.99, 0.99, 'APOGEE', ha='right', va='top', transform=ax1[0].transAxes)

ax1[1].scatter_density(gal_sel['bp_rp'], gal_sel['absmag'], cmap=colormapsT['all'], norm=norm)
ax1[1].scatter_density(gal_sel.loc[gal_sel['filter']]['bp_rp'], gal_sel.loc[gal_sel['filter']]['absmag'],
                      cmap=colormapsT['green'], norm=norm)
ax1[1].scatter_density(gal_sel.loc[gal_sel['cm_mainsequence']]['bp_rp'], gal_sel.loc[gal_sel['cm_mainsequence']]['absmag'],
                      cmap=colormapsT['blue'], norm=norm)
ax1[1].scatter_density(gal_sel.loc[gal_sel['cm_giants']]['bp_rp'], gal_sel.loc[gal_sel['cm_giants']]['absmag'],
                      cmap=colormapsT['red'], norm=norm)
ax1[1].add_patch(mpatches.Polygon(cm_giants_cut, **polyconf))
ax1[1].add_patch(mpatches.Polygon(cm_mainseq_cut, **polyconf))
ax1[1].text(0.99, 0.99, 'GALAH', ha='right', va='top', transform=ax1[1].transAxes)

ax1[0].set_xlim([-0.41, 4.2])
ax1[0].set_ylim([14.4, -5])
ax1[1].yaxis.set_visible(False)
f1.supxlabel('BP-RP [mag]', fontsize=10)
f1.supylabel('G [mag]', fontsize=10)
patches = [mpatches.Patch(color='gray', label='survey + GDR3 rv'),
           mpatches.Patch(color='green', label='Fe and Mg quality filter'),
           mpatches.Patch(color='blue', label='selected MS'),
           mpatches.Patch(color='red', label='selected RGB'),
           Line2D([0], [0], color='k', lw=1.5, ls='--', label='CM selection polygons')]
ax1[0].legend(handles=patches, bbox_to_anchor=(0.05, 1.03), loc='lower left', fontsize=8, ncol=3)
plt.tight_layout()
plt.subplots_adjust(top=0.85,
bottom=0.156,
left=0.1,
right=0.974,
hspace=0.2,
wspace=0.07)
plt.show()