Regarding scatter plot with contours over dense regions.

98 views
Skip to first unread message

FELIX FRANCIS

unread,
Aug 5, 2014, 6:56:30 PM8/5/14
to astroml...@googlegroups.com
Hi,

I came across the python source code for generating a scatter plot with contours over dense regions (http://www.astroml.org/book_figures/chapter1/fig_S82_scatter_contour.html)
Please let me know how a color bar corresponding to the contour plot can be included in this figure.

Felix


#####

# Author: Jake VanderPlas
# License: BSD
#   The figure produced by this code is published in the textbook
#   "Statistics, Data Mining, and Machine Learning in Astronomy" (2013)
#   For more information, see http://astroML.github.com
#   To report a bug or issue, use the following forum:
#    https://groups.google.com/forum/#!forum/astroml-general
from matplotlib import pyplot as plt

from astroML.plotting import scatter_contour
from astroML.datasets import fetch_sdss_S82standards

#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
from astroML.plotting import setup_text_plots
setup_text_plots(fontsize=8, usetex=True)

#------------------------------------------------------------
# Fetch the Stripe 82 standard star catalog

data = fetch_sdss_S82standards()

g = data['mmu_g']
r = data['mmu_r']
i = data['mmu_i']

#------------------------------------------------------------
# plot the results
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()

Jake Vanderplas

unread,
Aug 5, 2014, 7:09:49 PM8/5/14
to FELIX FRANCIS, astroml...@googlegroups.com
Hi,
This is not possible (or perhaps very hard) with the released version of astroML, but the master version has been modified to make it easy. You'll have to install from the source, which you can find on http://github.com/astroml/astroml

Once you've done this, modify the example code to store the result of the scatter_contour function; e.g.

   points, contours = scatter_contour( ... )

Then you can do 

   plt.colorbar(contours)

and you'll see the associated colorbar on the current figure.

Hope that helps!
   Jake


--
You received this message because you are subscribed to the Google Groups "astroML-general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astroml-gener...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages