class: center, middle, inverse, title-slide # A Python Flipbook ## With {flipbookr} and xaringan ### Gina Reynolds, March 2020 --- This is pretty experimental work. The python "parser" (basically no parsing) means there are strong constraints on code. Each new line must yield complete code statement... <!-- This next chunk is just for the developer -- working w/ local code --> ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` ``` Error in file(filename, "r", encoding = encoding) : cannot open the connection ``` --- count: false .panel1-hello_python-auto[ ```python *[1, 4] * 8 ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 *3 + 4 * 8 ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 *2 + 6 ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 2 + 6 *4 * 8 ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ``` 32 ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 2 + 6 4 * 8 *[1,2] + [3,4,5,6] ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ``` 32 ``` ``` [1, 2, 3, 4, 5, 6] ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 2 + 6 4 * 8 [1,2] + [3,4,5,6] *["hello", "world!", 1, 2, 3] * 2 ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ``` 32 ``` ``` [1, 2, 3, 4, 5, 6] ``` ``` ['hello', 'world!', 1, 2, 3, 'hello', 'world!', 1, 2, 3] ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 2 + 6 4 * 8 [1,2] + [3,4,5,6] ["hello", "world!", 1, 2, 3] * 2 *import numpy as np ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ``` 32 ``` ``` [1, 2, 3, 4, 5, 6] ``` ``` ['hello', 'world!', 1, 2, 3, 'hello', 'world!', 1, 2, 3] ``` ] --- count: false .panel1-hello_python-auto[ ```python [1, 4] * 8 3 + 4 * 8 2 + 6 4 * 8 [1,2] + [3,4,5,6] ["hello", "world!", 1, 2, 3] * 2 import numpy as np *np.reshape(np.arange(1,25), * (4,3,2), "F") ``` ] .panel2-hello_python-auto[ ``` [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4] ``` ``` 35 ``` ``` 8 ``` ``` 32 ``` ``` [1, 2, 3, 4, 5, 6] ``` ``` ['hello', 'world!', 1, 2, 3, 'hello', 'world!', 1, 2, 3] ``` ``` array([[[ 1, 13], [ 5, 17], [ 9, 21]], [[ 2, 14], [ 6, 18], [10, 22]], [[ 3, 15], [ 7, 19], [11, 23]], [[ 4, 16], [ 8, 20], [12, 24]]]) ``` ] <style> .panel1-hello_python-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-hello_python-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-hello_python-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-simple_plot-auto[ ```python *import matplotlib.pyplot as plt ``` ] .panel2-simple_plot-auto[ ] --- count: false .panel1-simple_plot-auto[ ```python import matplotlib.pyplot as plt *year = [1950, 1970, * 1990, 2010] ``` ] .panel2-simple_plot-auto[ ] --- count: false .panel1-simple_plot-auto[ ```python import matplotlib.pyplot as plt year = [1950, 1970, 1990, 2010] *pop = [2.519, 3, 5, 6] ``` ] .panel2-simple_plot-auto[ ] --- count: false .panel1-simple_plot-auto[ ```python import matplotlib.pyplot as plt year = [1950, 1970, 1990, 2010] pop = [2.519, 3, 5, 6] *plt.plot(year, pop); plt.show() ``` ] .panel2-simple_plot-auto[ ![](python-flipbook_files/figure-html/simple_plot_auto_04_output-1.svg)<!-- -->![](python-flipbook_files/figure-html/simple_plot_auto_04_output-2.svg)<!-- --> ] <style> .panel1-simple_plot-auto { color: black; width: 58.4040404040404%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-simple_plot-auto { color: black; width: 39.5959595959596%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-simple_plot-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-numpy-auto[ ```python *# import pandas as pd ``` ] .panel2-numpy-auto[ ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd *import matplotlib.pyplot as plt ``` ] .panel2-numpy-auto[ ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd import matplotlib.pyplot as plt *import numpy as np ``` ] .panel2-numpy-auto[ ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd import matplotlib.pyplot as plt import numpy as np *t = np.arange(0, 2, .05) ``` ] .panel2-numpy-auto[ ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd import matplotlib.pyplot as plt import numpy as np t = np.arange(0, 2, .05) *t ``` ] .panel2-numpy-auto[ ``` array([0. , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1. , 1.05, 1.1 , 1.15, 1.2 , 1.25, 1.3 , 1.35, 1.4 , 1.45, 1.5 , 1.55, 1.6 , 1.65, 1.7 , 1.75, 1.8 , 1.85, 1.9 , 1.95]) ``` ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd import matplotlib.pyplot as plt import numpy as np t = np.arange(0, 2, .05) t *s = np.sin(2*np.pi*t) ``` ] .panel2-numpy-auto[ ``` array([0. , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1. , 1.05, 1.1 , 1.15, 1.2 , 1.25, 1.3 , 1.35, 1.4 , 1.45, 1.5 , 1.55, 1.6 , 1.65, 1.7 , 1.75, 1.8 , 1.85, 1.9 , 1.95]) ``` ] --- count: false .panel1-numpy-auto[ ```python # import pandas as pd import matplotlib.pyplot as plt import numpy as np t = np.arange(0, 2, .05) t s = np.sin(2*np.pi*t) *s ``` ] .panel2-numpy-auto[ ``` array([0. , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1. , 1.05, 1.1 , 1.15, 1.2 , 1.25, 1.3 , 1.35, 1.4 , 1.45, 1.5 , 1.55, 1.6 , 1.65, 1.7 , 1.75, 1.8 , 1.85, 1.9 , 1.95]) ``` ``` array([ 0.00000000e+00, 3.09016994e-01, 5.87785252e-01, 8.09016994e-01, 9.51056516e-01, 1.00000000e+00, 9.51056516e-01, 8.09016994e-01, 5.87785252e-01, 3.09016994e-01, 1.22464680e-16, -3.09016994e-01, -5.87785252e-01, -8.09016994e-01, -9.51056516e-01, -1.00000000e+00, -9.51056516e-01, -8.09016994e-01, -5.87785252e-01, -3.09016994e-01, -2.44929360e-16, 3.09016994e-01, 5.87785252e-01, 8.09016994e-01, 9.51056516e-01, 1.00000000e+00, 9.51056516e-01, 8.09016994e-01, 5.87785252e-01, 3.09016994e-01, 3.67394040e-16, -3.09016994e-01, -5.87785252e-01, -8.09016994e-01, -9.51056516e-01, -1.00000000e+00, -9.51056516e-01, -8.09016994e-01, -5.87785252e-01, -3.09016994e-01]) ``` ] <style> .panel1-numpy-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-numpy-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-numpy-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-numpy2-auto[ ```python *plt.plot(t, s) ``` ] .panel2-numpy2-auto[ ![](python-flipbook_files/figure-html/numpy2_auto_01_output-1.svg)<!-- --> ] --- count: false .panel1-numpy2-auto[ ```python plt.plot(t, s) *plt.xlabel('time (s)') ``` ] .panel2-numpy2-auto[ ![](python-flipbook_files/figure-html/numpy2_auto_02_output-1.svg)<!-- --> ] --- count: false .panel1-numpy2-auto[ ```python plt.plot(t, s) plt.xlabel('time (s)') *plt.ylabel('voltage (mV)') ``` ] .panel2-numpy2-auto[ ![](python-flipbook_files/figure-html/numpy2_auto_03_output-1.svg)<!-- --> ] --- count: false .panel1-numpy2-auto[ ```python plt.plot(t, s) plt.xlabel('time (s)') plt.ylabel('voltage (mV)') *plt.grid(True); plt.show() ``` ] .panel2-numpy2-auto[ ![](python-flipbook_files/figure-html/numpy2_auto_04_output-1.svg)<!-- --> ] <style> .panel1-numpy2-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-numpy2-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-numpy2-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> <style type="text/css"> .remark-code{line-height: 1.5; font-size: 80%} @media print { .has-continuation { display: block; } } </style>