%pylab inline
%load http://www.astroml.org/_downloads/fig_prob_sum.py
"""
Sum of Probabilities
--------------------
Figure 3.1.
A representation of the sum of probabilities shown in eq.3.1.
"""
# 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
#----------------------------------------------------------------------
# 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)
# create plot
fig = plt.figure(figsize=(5, 3.75), facecolor='w')
ax = plt.axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
# draw intersecting circles
ax.add_patch(plt.Circle((1.5, 0.2), 2.2, fc='gray', ec='black', alpha=0.5))
ax.add_patch(plt.Circle((-1.5, 0.2), 2.2, fc='gray', ec='black', alpha=0.5))
# add text
text_kwargs = dict(ha='center', va='center', fontsize=12)
ax.text(-1.6, 0.2, "$p(A)$", **text_kwargs)
ax.text(1.6, 0.2, "$p(B)$", **text_kwargs)
ax.text(0.0, 0.2, "$p(A \cap B)$", **text_kwargs)
ax.text(0, -2.3, "$p(A \cup B) = p(A) + p(B) - p(A \cap B)$", **text_kwargs)
ax.set_xlim(-4, 4)
ax.set_ylim(-3, 3)
plt.show()
The key takeaways from this figure:
Let's practice python by modifying the figure in a superficial but informative way. We will recreate Drew Conway's data science Venn Diagram, modified to be astronomy specific.
"""
Astronomy Data Science Venn Diagram
--------------------
Modified from Figure 3.1 of the astroML book,
and Drew Conway's data science Venn Diagram:
http://drewconway.com/zia/2013/3/26/the-data-science-venn-diagram
"""
# Edited by: gully
# For more information, see http://www.github.com/gully/astroMLfigs
from matplotlib import pyplot as plt
# create plot
fig = plt.figure(figsize=(8, 8), facecolor='#dddddd')
ax = plt.axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
# draw intersecting circles
ax.add_patch(plt.Circle((1.3, 1.5), radius=2.2, fc='green', ec='black', alpha=0.3))
ax.add_patch(plt.Circle((-1.3, 1.5), radius=2.2, fc='red', ec='black', alpha=0.3))
ax.add_patch(plt.Circle((0, -0.6), radius=2.2, fc='blue', ec='black', alpha=0.3))
# add text
text_kwargs = dict(ha='center', va='center', fontsize=22)
ax.text(-2.0, 2.0, "Python", rotation=40, **text_kwargs)
ax.text(2.0, 2.0, "Statistics", rotation=-40, **text_kwargs)
ax.text(0, -1.3, "Astronomy", **text_kwargs)
ax.text(0, 2.3, "scipy.stats", fontsize=16, ha='center', va='center')
ax.text(1.2, -0.1, "Traditional \n research", fontsize=16, ha='center', va='center')
ax.text(-1.2, -0.1, "Retractions", fontsize=16, ha='center', va='center')
ax.text(0, 0.9, "astroML", fontsize=16, ha='center', va='center')
ax.set_xlim(-4, 4)
ax.set_ylim(-4, 4)
plt.show()