Overplotting different data sets on one plot

My code currently calls in spectral types through Vizier Query, and plots them on a Mollweide projection. I’m trying to overplot all seven spectral types onto one image, but they all come up seperately. Any help on putting them all on one plot?

My current code:

sptypes = {'O*':'b','B*':'g','A*':'r','F*':'c','G*':'m','K*':'y','M*':'w'}

for sptype in sptypes.keys():

    Vizier.ROW_LIMIT = -1
    V_O = Vizier.query_constraints(catalog='I/131A', SpType=sptype)
    tbl = V_O[0]
    #print(tbl.colnames)

    tbl = tbl[tbl['SpType'] != '']

    #print(tbl['_RA.icrs'][:4])
    #print(tbl['_DE.icrs'][:4])
    coords = SkyCoord(tbl['_RA.icrs'], tbl['_DE.icrs'],
                  unit=(u.hourangle, u.degree),
                  frame='icrs')

    fig, ax = plt.subplots(1, 1, figsize=(10, 6), 
                       subplot_kw=dict(projection='aitoff'))
    ax.scatter(coords.ra.wrap_at(180*u.deg).radian,
           coords.dec.radian,
           alpha=0.5, s=4, )

plt.title("SAO Stars")
plt.grid(True)
plt.show()

Hi @jrmusiov

Try moving the subplot command outside of the loop. You should only be creating your figure and axes once and then referencing those within the loop.

fig, ax = plt.subplots(....)
for sptype in sptypes.keys():
    :
    :
    ax.scatter(....)

This should fix your problem.

HtH
Laurence

2 Likes

Thank you @laurence.molloy! That did work, I tried moving it before but it was to the wrong spot.

Much appreciated!