Please let me know how I could include a contour plot color bar in the following figure:
from matplotlib import pyplot as plt
from astroML.plotting import scatter_contour
from astroML.datasets import fetch_sdss_S82standards
data = fetch_sdss_S82standards()
g = data['mmu_g']
r = data['mmu_r']
i = data['mmu_i']
fig, ax = plt.subplots(figsize=(5, 3.75))
scatter_contour(g - r, r - i, threshold=200, log_counts=True, ax=ax,
histogram2d_args=dict(bins=40),
plot_args=dict(marker=',', linestyle='none', color='black'),
contour_args=dict(cmap=plt.cm.bone))
ax.set_xlabel(r'${\rm g - r}$')
ax.set_ylabel(r'${\rm r - i}$')
ax.set_xlim(-0.6, 2.5)
ax.set_ylim(-0.6, 2.5)
plt.show()
I tried cbar = plt.colorbar() I am getting the error: No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf).
scatter_contour
return? I'm unfamiliar with astroML, but if it returns something akin to what imshow returns, you can just assign it to a variable and pass it e.g.plt.colorbar(im)
– Ajean