1

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).

1
  • 1
    What does 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) Commented Aug 5, 2014 at 23:22

1 Answer 1

2

If you have write access to the source, then you can change the line in scatter_contour to return the contour set you need:

CS = ax.contourf(H.T, levels, extent=extent, **contour_args)

...

return CS

and then you can make your colorbar by calling

CS = scatter_contour(...)
colorbar(CS)

If you can't, then you'd have to try trace the references of the collections held in the axes - not immediately sure how to do this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.