Updating notebooks

This commit is contained in:
Allen Downey
2020-10-15 14:35:03 -04:00
parent 2e16d77bc2
commit caa032e8b2
10 changed files with 573 additions and 514 deletions

View File

@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"## Lesson 7\n",
"\n",
"This is the seventh in a series of lessons related to astronomy data.\n",
"\n",
@@ -19,8 +19,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lesson 7\n",
"\n",
"Here are the steps in this notebook:\n",
"\n",
"1. Starting with the figure from the previous notebook, we'll add annotations to present the results more clearly.\n",
@@ -55,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -65,8 +63,7 @@
"IN_COLAB = 'google.colab' in sys.modules\n",
"\n",
"if IN_COLAB:\n",
" !pip install astroquery astro-gala pyia\n",
" !mkdir data"
" !pip install astroquery astro-gala pyia python-wget"
]
},
{
@@ -131,56 +128,36 @@
"source": [
"## Plotting GD-1\n",
"\n",
"Let's focus on the figure in the lower left..."
"Let's start with the panel in the lower left. The following cell reloads the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2020-10-05 10:24:55-- https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5\n",
"Resolving github.com (github.com)... 140.82.112.4\n",
"Connecting to github.com (github.com)|140.82.112.4|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5 [following]\n",
"--2020-10-05 10:24:56-- https://raw.githubusercontent.com/AllenDowney/AstronomicalData/main/data/gd1_merged.hdf5\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.116.133\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.116.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 2006352 (1.9M) [application/octet-stream]\n",
"Saving to: gd1_merged.hdf5\n",
"\n",
"gd1_merged.hdf5 100%[===================>] 1.91M 6.14MB/s in 0.3s \n",
"\n",
"2020-10-05 10:24:56 (6.14 MB/s) - gd1_merged.hdf5 saved [2006352/2006352]\n",
"\n"
"gd1_merged.hdf5\n"
]
}
],
"source": [
"import os\n",
"from wget import download\n",
"\n",
"filename = 'gd1_merged.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_merged.hdf5"
" print(download(path+filename))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -191,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@@ -219,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -267,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -326,7 +303,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -348,7 +325,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [
{
@@ -357,15 +334,13 @@
"10.0"
]
},
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import matplotlib as mpl\n",
"\n",
"mpl.rcParams['font.size']"
"plt.rcParams['font.size']"
]
},
{
@@ -377,11 +352,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"mpl.rcParams['font.size'] = 14"
"plt.rcParams['font.size'] = 14"
]
},
{
@@ -415,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"outputs": [
{
@@ -449,7 +424,7 @@
" 'tableau-colorblind10']"
]
},
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
@@ -464,17 +439,19 @@
"source": [
"Note that `seaborn-paper`, `seaborn-talk` and `seaborn-poster` are particularly intended to prepare versions of a figure with text sizes and other features that work well in papers, talks, and posters.\n",
"\n",
"To use any of these style sheets, run `plt.style.use` like this:"
"To use any of these style sheets, run `plt.style.use` like this:\n",
"\n",
"```\n",
"plt.style.use('fivethirtyeight')\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('fivethirtyeight')"
]
"source": []
},
{
"cell_type": "markdown",
@@ -491,21 +468,7 @@
"source": [
"If you can't find a style sheet that's exactly what you want, you can make your own. This repository includes a style sheet called `az-paper-twocol.mplstyle`, with customizations chosen by Azalee Bostroem for publication in astronomy journals.\n",
"\n",
"You can use it like this:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"filename = 'az-paper-twocol.mplstyle'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/az-paper-twocol.mplstyle"
"The following cell downloads the style sheet."
]
},
{
@@ -514,31 +477,66 @@
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('./az-paper-twocol.mplstyle')"
"import os\n",
"\n",
"filename = 'az-paper-twocol.mplstyle'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" print(download(path+filename))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The prefix `./` tells Matplotlib to look for the file in the current directory.\n",
"You can use it like this:\n",
"\n",
"As an alternative, you can install a style sheet for your own use by putting it in your configuration directory. To find out where that is, you can run the following command:"
"```\n",
"plt.style.use('./az-paper-twocol.mplstyle')\n",
"```\n",
"\n",
"The prefix `./` tells Matplotlib to look for the file in the current directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The prefix `./` tells Matplotlib to look for the file in the current directory.\n",
"\n",
"As an alternative, you can install a style sheet for your own use by putting it in your configuration directory. To find out where that is, you can run the following command:\n",
"\n",
"```\n",
"import matplotlib as mpl\n",
"\n",
"mpl.get_configdir()\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/home/downey/.config/matplotlib'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
@@ -555,16 +553,32 @@
"text.usetex : true\n",
"```\n",
"\n",
"Or in a notebook you can run the following cell."
"Or in a notebook you can run the following code.\n",
"\n",
"```\n",
"plt.rcParams['text.usetex'] = True\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'plt' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-79831e1d619c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrcParams\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'text.usetex'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'plt' is not defined"
]
}
],
"source": [
"mpl.rcParams['text.usetex'] = True"
"plt.rcParams['text.usetex'] = True"
]
},
{
@@ -623,9 +637,10 @@
"import os\n",
"\n",
"filename = 'gd1_dataframe.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_dataframe.hdf5"
" print(download(path+filename))"
]
},
{
@@ -754,7 +769,7 @@
}
],
"source": [
"mpl.rcParams['text.usetex'] = False\n",
"plt.rcParams['text.usetex'] = False\n",
"plt.style.use('default')\n",
"\n",
"plot_proper_motion(centerline)"
@@ -778,9 +793,10 @@
"import os\n",
"\n",
"filename = 'gd1_candidates.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_candidates.hdf5"
" print(download(path+filename))"
]
},
{
@@ -951,9 +967,10 @@
"import os\n",
"\n",
"filename = 'gd1_polygon.hdf5'\n",
"path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'\n",
"\n",
"if not os.path.exists(filename):\n",
" !wget https://github.com/AllenDowney/AstronomicalData/raw/main/data/gd1_polygon.hdf5"
" print(download(path+filename))"
]
},
{