Altering book format

Changed rest of chapters to use new formatting style. Also,
there is a bug in the current release of Jupyter that overwrites
the rcParams settings when you do the first import, so I had to
split the book format cell into two. This is actually better because
now the PDF, which strips out the formatting cell, will still have
the %matplotlib inline and import from future code.

Also, in the process of refactoring the information about Gaussian
and Bayes. Stuff is still strewn around too much. I need to make
this more streamlined. Chapters 2-4 talk about distributions, Bayes,
and Gaussians, and material is repeated a lot.
This commit is contained in:
Roger Labbe 2018-08-05 09:20:48 -07:00
parent 909f107a93
commit 5512aceaef
25 changed files with 3002 additions and 7007 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -25,254 +25,9 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
"@import url('http://fonts.googleapis.com/css?family=Lora');\n",
"\n",
".CodeMirror pre {\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
"}\n",
" div.cell{\n",
" //width: 950px;\n",
" margin-left: 0% !important;\n",
" margin-right: auto;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: 'Lora';\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" text-align: justify;\n",
" text-justify:inter-word;\n",
" }\n",
" div.text_cell code {\n",
" background: transparent;\n",
" color: #000000;\n",
" font-weight: 400;\n",
" font-size: 11pt;\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
" }\n",
" h1 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
"\t}\n",
"\n",
" div.input_area {\n",
" background: #F6F6F9;\n",
" border: 1px solid #586e75;\n",
" }\n",
"\n",
" .text_cell_render h1 {\n",
" font-weight: 200;\n",
" font-size: 30pt;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h2 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" text-align: left;\n",
" }\n",
" .text_cell_render h2 {\n",
" font-weight: 200;\n",
" font-size: 16pt;\n",
" font-style: italic;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1.5em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h3 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h3 {\n",
" font-weight: 200;\n",
" font-size: 14pt;\n",
" line-height: 100%;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 2em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h4 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h4 {\n",
" font-weight: 100;\n",
" font-size: 14pt;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" h5 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
"\n",
" .text_cell_render h5 {\n",
" font-weight: 200;\n",
" font-style: normal;\n",
" color: #1d3b84;\n",
" font-size: 16pt;\n",
" margin-bottom: 0em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" div.output_subarea.output_text.output_pyout {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_subarea.output_stream.output_stdout.output_text {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_wrapper{\n",
" margin-top:0.2em;\n",
" margin-bottom:0.2em;\n",
"}\n",
"\n",
" code{\n",
" font-size: 6pt;\n",
"\n",
" }\n",
" .rendered_html code{\n",
" background-color: transparent;\n",
" }\n",
" ul{\n",
" margin: 2em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li li{\n",
" padding-left: 0.2em;\n",
" margin-bottom: 0.2em;\n",
" margin-top: 0.2em;\n",
" }\n",
" ol{\n",
" margin: 2em;\n",
" }\n",
" ol li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.2em;\n",
" }\n",
" a:link{\n",
" color:#447adb;\n",
" }\n",
" a:visited{\n",
" color: #1d3b84;\n",
" }\n",
" a:hover{\n",
" color: #1d3b84;\n",
" }\n",
" a:focus{\n",
" color:#447adb;\n",
" }\n",
" a:active{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" .rendered_html :link {\n",
" text-decoration: underline;\n",
" }\n",
" .rendered_html :hover {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :visited {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :focus {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :active {\n",
" text-decoration: none;\n",
" }\n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" }\n",
" hr {\n",
" color: #f3f3f3;\n",
" background-color: #f3f3f3;\n",
" height: 1px;\n",
" }\n",
" blockquote{\n",
" display:block;\n",
" background: #fcfcfc;\n",
" border-left: 5px solid #c76c0c;\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" width:680px;\n",
" padding: 10px 10px 10px 10px;\n",
" text-align:justify;\n",
" text-justify:inter-word;\n",
" }\n",
" blockquote p {\n",
" margin-bottom: 0;\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" }\n",
"</style>\n",
"<script>\n",
" MathJax.Hub.Config({\n",
" TeX: {\n",
" extensions: [\"AMSmath.js\"],\n",
" equationNumbers: { autoNumber: \"AMS\", useLabelIds: true}\n",
" },\n",
" tex2jax: {\n",
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
" },\n",
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
" \"HTML-CSS\": {\n",
" scale: 95,\n",
" availableFonts: [],\n",
" preferredFont:null,\n",
" webFont: \"TeX\",\n",
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
" },\n",
" \"fast-preview\": {\n",
" \"disabled\": false\n",
" }\n",
" });\n",
"</script>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#format the book\n",
"%matplotlib inline\n",
"from __future__ import division, print_function\n",
"from book_format import load_style\n",
"load_style()"
"from __future__ import division, print_function"
]
},
{
@ -756,7 +511,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,

View File

@ -7,258 +7,6 @@
"[Table of Contents](./table_of_contents.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
"@import url('http://fonts.googleapis.com/css?family=Lora');\n",
"\n",
".CodeMirror pre {\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
"}\n",
" div.cell{\n",
" //width: 950px;\n",
" margin-left: 0% !important;\n",
" margin-right: auto;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: 'Lora';\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" text-align: justify;\n",
" text-justify:inter-word;\n",
" }\n",
" div.text_cell code {\n",
" background: transparent;\n",
" color: #000000;\n",
" font-weight: 400;\n",
" font-size: 11pt;\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
" }\n",
" h1 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
"\t}\n",
"\n",
" div.input_area {\n",
" background: #F6F6F9;\n",
" border: 1px solid #586e75;\n",
" }\n",
"\n",
" .text_cell_render h1 {\n",
" font-weight: 200;\n",
" font-size: 30pt;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h2 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" text-align: left;\n",
" }\n",
" .text_cell_render h2 {\n",
" font-weight: 200;\n",
" font-size: 16pt;\n",
" font-style: italic;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1.5em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h3 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h3 {\n",
" font-weight: 200;\n",
" font-size: 14pt;\n",
" line-height: 100%;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 2em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h4 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h4 {\n",
" font-weight: 100;\n",
" font-size: 14pt;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" h5 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
"\n",
" .text_cell_render h5 {\n",
" font-weight: 200;\n",
" font-style: normal;\n",
" color: #1d3b84;\n",
" font-size: 16pt;\n",
" margin-bottom: 0em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" div.output_subarea.output_text.output_pyout {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_subarea.output_stream.output_stdout.output_text {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_wrapper{\n",
" margin-top:0.2em;\n",
" margin-bottom:0.2em;\n",
"}\n",
"\n",
" code{\n",
" font-size: 6pt;\n",
"\n",
" }\n",
" .rendered_html code{\n",
" background-color: transparent;\n",
" }\n",
" ul{\n",
" margin: 2em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li li{\n",
" padding-left: 0.2em;\n",
" margin-bottom: 0.2em;\n",
" margin-top: 0.2em;\n",
" }\n",
" ol{\n",
" margin: 2em;\n",
" }\n",
" ol li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.2em;\n",
" }\n",
" a:link{\n",
" color:#447adb;\n",
" }\n",
" a:visited{\n",
" color: #1d3b84;\n",
" }\n",
" a:hover{\n",
" color: #1d3b84;\n",
" }\n",
" a:focus{\n",
" color:#447adb;\n",
" }\n",
" a:active{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" .rendered_html :link {\n",
" text-decoration: underline;\n",
" }\n",
" .rendered_html :hover {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :visited {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :focus {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :active {\n",
" text-decoration: none;\n",
" }\n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" }\n",
" hr {\n",
" color: #f3f3f3;\n",
" background-color: #f3f3f3;\n",
" height: 1px;\n",
" }\n",
" blockquote{\n",
" display:block;\n",
" background: #fcfcfc;\n",
" border-left: 5px solid #c76c0c;\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" width:680px;\n",
" padding: 10px 10px 10px 10px;\n",
" text-align:justify;\n",
" text-justify:inter-word;\n",
" }\n",
" blockquote p {\n",
" margin-bottom: 0;\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" }\n",
"</style>\n",
"<script>\n",
" MathJax.Hub.Config({\n",
" TeX: {\n",
" extensions: [\"AMSmath.js\"],\n",
" equationNumbers: { autoNumber: \"AMS\", useLabelIds: true}\n",
" },\n",
" tex2jax: {\n",
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
" },\n",
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
" \"HTML-CSS\": {\n",
" scale: 95,\n",
" availableFonts: [],\n",
" preferredFont:null,\n",
" webFont: \"TeX\",\n",
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
" },\n",
" \"fast-preview\": {\n",
" \"disabled\": false\n",
" }\n",
" });\n",
"</script>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#format the book\n",
"from book_format import load_style\n",
"load_style()"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -362,7 +110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,254 +18,46 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from __future__ import division, print_function"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
"@import url('http://fonts.googleapis.com/css?family=Lora');\n",
"\n",
".CodeMirror pre {\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
"}\n",
" div.cell{\n",
" //width: 950px;\n",
" margin-left: 0% !important;\n",
" margin-right: auto;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: 'Lora';\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" text-align: justify;\n",
" text-justify:inter-word;\n",
" }\n",
" div.text_cell code {\n",
" background: transparent;\n",
" color: #000000;\n",
" font-weight: 400;\n",
" font-size: 11pt;\n",
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
" }\n",
" h1 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
"\t}\n",
"\n",
" div.input_area {\n",
" background: #F6F6F9;\n",
" border: 1px solid #586e75;\n",
" }\n",
"\n",
" .text_cell_render h1 {\n",
" font-weight: 200;\n",
" font-size: 30pt;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h2 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" text-align: left;\n",
" }\n",
" .text_cell_render h2 {\n",
" font-weight: 200;\n",
" font-size: 16pt;\n",
" font-style: italic;\n",
" line-height: 100%;\n",
" color:#c76c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 1.5em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h3 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h3 {\n",
" font-weight: 200;\n",
" font-size: 14pt;\n",
" line-height: 100%;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 2em;\n",
" display: block;\n",
" white-space: wrap;\n",
" text-align: left;\n",
" }\n",
" h4 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h4 {\n",
" font-weight: 100;\n",
" font-size: 14pt;\n",
" color:#d77c0c;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" h5 {\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" }\n",
"\n",
" .text_cell_render h5 {\n",
" font-weight: 200;\n",
" font-style: normal;\n",
" color: #1d3b84;\n",
" font-size: 16pt;\n",
" margin-bottom: 0em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" div.output_subarea.output_text.output_pyout {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_subarea.output_stream.output_stdout.output_text {\n",
" overflow-x: auto;\n",
" overflow-y: visible;\n",
" max-height: 5000000px;\n",
" }\n",
" div.output_wrapper{\n",
" margin-top:0.2em;\n",
" margin-bottom:0.2em;\n",
"}\n",
"\n",
" code{\n",
" font-size: 6pt;\n",
"\n",
" }\n",
" .rendered_html code{\n",
" background-color: transparent;\n",
" }\n",
" ul{\n",
" margin: 2em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li li{\n",
" padding-left: 0.2em;\n",
" margin-bottom: 0.2em;\n",
" margin-top: 0.2em;\n",
" }\n",
" ol{\n",
" margin: 2em;\n",
" }\n",
" ol li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.2em;\n",
" }\n",
" a:link{\n",
" color:#447adb;\n",
" }\n",
" a:visited{\n",
" color: #1d3b84;\n",
" }\n",
" a:hover{\n",
" color: #1d3b84;\n",
" }\n",
" a:focus{\n",
" color:#447adb;\n",
" }\n",
" a:active{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" .rendered_html :link {\n",
" text-decoration: underline;\n",
" }\n",
" .rendered_html :hover {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :visited {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :focus {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :active {\n",
" text-decoration: none;\n",
" }\n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" }\n",
" hr {\n",
" color: #f3f3f3;\n",
" background-color: #f3f3f3;\n",
" height: 1px;\n",
" }\n",
" blockquote{\n",
" display:block;\n",
" background: #fcfcfc;\n",
" border-left: 5px solid #c76c0c;\n",
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
" width:680px;\n",
" padding: 10px 10px 10px 10px;\n",
" text-align:justify;\n",
" text-justify:inter-word;\n",
" }\n",
" blockquote p {\n",
" margin-bottom: 0;\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" }\n",
"</style>\n",
"<script>\n",
" MathJax.Hub.Config({\n",
" TeX: {\n",
" extensions: [\"AMSmath.js\"],\n",
" equationNumbers: { autoNumber: \"AMS\", useLabelIds: true}\n",
" },\n",
" tex2jax: {\n",
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
" },\n",
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
" \"HTML-CSS\": {\n",
" scale: 95,\n",
" availableFonts: [],\n",
" preferredFont:null,\n",
" webFont: \"TeX\",\n",
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
" },\n",
" \"fast-preview\": {\n",
" \"disabled\": false\n",
" }\n",
" });\n",
"</script>\n"
" <style>\n",
" .output_wrapper, .output {\n",
" height:auto !important;\n",
" max-height:100000px; \n",
" }\n",
" .output_scroll {\n",
" box-shadow:none !important;\n",
" webkit-box-shadow:none !important;\n",
" }\n",
" </style>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#format the book\n",
"%matplotlib inline\n",
"from __future__ import division, print_function\n",
"from book_format import load_style\n",
"load_style()"
"import book_format\n",
"book_format.set_style()"
]
},
{
@ -317,7 +109,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,

View File

@ -312,7 +312,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,

View File

@ -26,7 +26,7 @@ import numpy as np
import os.path
import sys
import warnings
from kf_book.book_plots import set_figsize, reset_axis
from kf_book.book_plots import set_figsize, reset_figsize
# version 1.4.3 of matplotlib has a bug that makes
# it issue a spurious warning on every plot that
@ -59,16 +59,14 @@ def test_filterpy_version():
test_filterpy_version()
pylab.rcParams['figure.max_open_warning'] = 50
pylab.rcParams['figure.figsize'] = 8, 3
@contextmanager
def numpy_precision(precision):
old = np.get_printoptions()['precision']
np.set_printoptions(precision=precision)
yield
np.set_printoptions(old)
old = np.get_printoptions()['precision']
np.set_printoptions(precision=precision)
yield
np.set_printoptions(old)
@contextmanager
def printoptions(*args, **kwargs):
@ -104,26 +102,37 @@ def _decode_dict(data):
return rv
def load_style(directory = '.', name='kf_book/custom.css'):
version = [int(version_no) for version_no in matplotlib.__version__.split('.')]
def set_style():
version = [int(version_no) for version_no in matplotlib.__version__.split('.')]
try:
if sys.version_info[0] >= 3:
style = json.load(open(os.path.join(directory, "kf_book/538.json")))
else:
style = json.load(open(directory + "/kf_book/538.json"), object_hook=_decode_dict)
plt.rcParams.update(style)
except:
pass
set_figsize()
reset_axis ()
np.set_printoptions(suppress=True, precision=3,
threshold=10000., linewidth=70,
formatter={'float':lambda x:' {:.3}'.format(x)})
styles = open(os.path.join(directory, name), 'r').read()
set_figsize()
# I don't know why I have to do this, but I have to call
# with suppress a second time or the notebook doesn't suppress
# exponents
np.set_printoptions(suppress=True)
return HTML(styles)
try:
if sys.version_info[0] >= 3:
style = json.load(open("./kf_book/538.json"))
else:
style = json.load(open(".//kf_book/538.json"), object_hook=_decode_dict)
plt.rcParams.update(style)
except:
pass
np.set_printoptions(suppress=True, precision=3,
threshold=10000., linewidth=70,
formatter={'float':lambda x:' {:.3}'.format(x)})
# I don't know why I have to do this, but I have to call
# with suppress a second time or the notebook doesn't suppress
# exponents
np.set_printoptions(suppress=True)
reset_figsize()
style = '''
<style>
.output_wrapper, .output {
height:auto !important;
max-height:100000px;
}
.output_scroll {
box-shadow:none !important;
webkit-box-shadow:none !important;
}
</style>
'''
return HTML(style)

View File

@ -34,31 +34,26 @@ except:
pass
def equal_axis(sz=10):
_default_size=(9, 4)
def equal_axis(sz=_default_size[0]):
""" set size of axis in inches, using the same for each"""
pylab.rcParams['figure.figsize'] = sz, sz
plt.axis('equal')
def reset_axis():
""" reest axis size in inches to the default size for the book"""
pylab.rcParams['figure.figsize'] = 8, 3
def reset_figsize():
""" reest axis size in inches to the default size for the book"""
pylab.rcParams['figure.figsize'] = 8, 3
mpl.rcParams['figure.figsize'] = _default_size
def set_figsize(x=10, y=4):
def set_figsize(x=_default_size[0], y=_default_size[1]):
""" set the figure size of the plot to the specified size in inches"""
pylab.rcParams['figure.figsize'] = x, y
mpl.rcParams['figure.figsize'] = x, y
@contextmanager
def figsize(x=8, y=3):
"""Temporarily set the figure size using 'with figsize(a,b):'"""
"""Temporarily set the figure size using 'with figsize(a, b):'"""
size = pylab.rcParams['figure.figsize']
set_figsize(x, y)
@ -75,37 +70,6 @@ type output into the notebook."""
IS_INLINE = mpl.get_backend().find('backend_inline') != -1
def end_interactive(fig):
""" end interaction in a plot created with %matplotlib notebook """
if IS_INLINE:
return
fig.canvas.draw()
time.sleep(1.)
plt.close(fig)
@contextmanager
def interactive_plot(close=True, fig=None):
if fig is None and not IS_INLINE:
fig = plt.figure()
yield
try:
# if the figure only uses annotations tight_output
# throws an exception
if not IS_INLINE: plt.tight_layout()
except:
pass
if not IS_INLINE:
plt.show()
if close and not IS_INLINE:
end_interactive(fig)
def plot_errorbars(bars, xlims, ylims=(-1, 1)):
"""Plots a list of error bars with optional x and y limits.
The list `bars` is a list of tuples (or any iterable) containing
@ -150,17 +114,17 @@ def plot_errorbars(bars, xlims, ylims=(-1, 1)):
def predict_update_chart(box_bg = '#CCCCCC',
arrow1 = '#88CCFF',
arrow2 = '#88FF88'):
plt.figure(figsize=(4,4), facecolor='w')
plt.figure(figsize=(4, 4), facecolor='w')
ax = plt.axes((0, 0, 1, 1),
xticks=[], yticks=[], frameon=False)
pc = Circle((4,5), 0.7, fc=box_bg)
uc = Circle((6,5), 0.7, fc=box_bg)
pc = Circle((4, 5), 0.7, fc=box_bg)
uc = Circle((6, 5), 0.7, fc=box_bg)
ax.add_patch (pc)
ax.add_patch (uc)
plt.text(4,5, "Predict\nStep",ha='center', va='center', fontsize=12)
plt.text(6,5, "Update\nStep",ha='center', va='center', fontsize=12)
plt.text(4, 5, "Predict\nStep",ha='center', va='center', fontsize=12)
plt.text(6, 5, "Update\nStep",ha='center', va='center', fontsize=12)
#btm arrow from update to predict
ax.annotate('',
@ -214,14 +178,14 @@ def predict_update_chart(box_bg = '#CCCCCC',
def show_residual_chart(show_eq=True, show_H=False):
plt.figure(figsize=(11, 3.), facecolor='w')
est_y = ((164.2-158)*.8 + 158)
est_y = ((164.2 - 158)*.8 + 158)
ax = plt.axes(xticks=[], yticks=[], frameon=False)
ax.annotate('', xy=[1,159], xytext=[0,158],
ax.annotate('', xy=[1,159], xytext=[0, 158],
arrowprops=dict(arrowstyle='->',
ec='r', lw=3, shrinkA=6, shrinkB=5))
ax.annotate('', xy=[1,159], xytext=[1,164.2],
ax.annotate('', xy=[1, 159], xytext=[1, 164.2],
arrowprops=dict(arrowstyle='-',
ec='k', lw=3, shrinkA=8, shrinkB=8))

View File

@ -27,7 +27,7 @@ def plot_height_std(x, lw=10):
for i, height in enumerate(x):
plt.plot([i+1, i+1], [0, height], color='k', lw=lw)
plt.xlim(0,len(x)+1)
plt.xlim(0, len(x)+1)
plt.axhline(m-s, ls='--')
plt.axhline(m+s, ls='--')
plt.fill_between((0, len(x)+1), m-s, m+s,