I'm trying to plot two subplots of hp.mollview projections with scatterplots, The first scatterplot shows up in the correct subfigure. But the second scatterplot shows up in both subfigures.
the code is:
import numpy as np
import matplotlib.pylab as plt
import matplotlib.cm as cm
import healpy as hp
import h5py
#generate random angular values
#1st scatter plot:
A=2*np.pi*(2*np.random.rand(200)-1)
B=np.pi/2*(2*np.random.rand(200)-1)
#2nd scatter plot:
C=2*np.pi*(2*np.random.rand(200)-1)
D=np.pi/2*(2*np.random.rand(200)-1)
fig, ax = plt.subplots(1,2,figsize=(12.5,10))
fig.tight_layout(pad=.0001,h_pad=.0001,w_pad=.0001)
plt.axes(ax[0])
hp.mollview(None,cbar=None,title=None,hold=True)
hp.graticule()
hp.projscatter(A,B,color='red',s=30)
plt.axes(ax[1])
hp.mollview(None,cbar=None,title=None,hold=True)
hp.graticule()
hp.projscatter(C,D,color='blue',s=30)
plt.show()
I tried so many things to reformulate e.g. with the subplots(121), subplots(122) format, but the second scatterplot somehow show up in both figures. This normally works and the issue is with mollview and projscatter since they can be somewhat nonconventional. There is one almost identical unanswered question about this on GitHub. Other than that I didn't find anything.
I ended up with a quick fix by saving the figures separately and plotting with imgread instead, but why does the second scatterplot behave like this?
Eventually, I asked one of the main contributors to healpy
, he answered on github and following his advice by using newprojview
I created these great subplots with the scatter-subplots showing nominal behaviour:
m = np.zeros(hp.nside2npix(32))
m2= np.random.random(hp.nside2npix(32))
projview(
m,
# cmap="planck",
graticule=True,
graticule_labels=True,
sub=221,
override_plot_properties={"figure_width": 13, "figure_size_ratio": 0.53},
cbar=None,
);
plt.scatter(np.deg2rad([0, -30, 30]), np.deg2rad([0,0,0]), color="red", s=80);
projview(
m,
# cmap="planck",
graticule=True,
graticule_labels=True,
cbar=None,
sub=222,
);
plt.tight_layout();
plt.scatter(np.deg2rad([90, 90, 90]), np.deg2rad([45,-45,0]), color="black", s=80);
projview(
m2,
cmap="planck",
sub=223,
);
plt.scatter(np.deg2rad([0, -30, 30]), np.deg2rad([30,30,30]), color="green", s=80);
projview(
m2,
cmap="planck",
sub=224,
);
plt.tight_layout();
plt.scatter(np.deg2rad([-30, -30, -30]), np.deg2rad([45,-45,0]), color="white", s=80);