使用Jupyter制作Slides的介绍#
王成军
计算传播网 http://computational-communication.com
使用Nbviewer打开Slides#
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/03-who-runs-China.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/0-jupyter-notebook.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/0-matplotlib-chinese.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/0-slides.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/0-turicreate.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/01-intro2cjc.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/02-bigdata.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/03-python-intro.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/03-UK-MPS-Scandal.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/03-umbrella-of-love.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-13chambers.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-beautifulsoup.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-cppcc.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-douban.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-fact-checking.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-gov-report.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-netease-music.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-pyppeteer.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-selenium.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-tripadvisor.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-wechat.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/04-crawler-weibo.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/06-data-cleaning-intro.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/06-data-cleaning-pandas.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/06-data-cleaning-tweets.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-01-statistics-thinking.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-02-kl-divergence.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-02-linear-algebra.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-03-distributions.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-03-probability.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-04-hypothesis-inference.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-05-gradient-descent.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-06-regression.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-06-statsmodels.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-07-covid19-pew-survey.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/08-09-survival-analysis.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-04-feature-engineering.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-05-naive-bayes.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-06-linear-regression.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-08-random-forests.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-09-googleflustudy.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-10-future-employment.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-11-neural-network-intro.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-12-hand-written-digits.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-13-cnn.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-14-rnn.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-15-cifar10.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/09-grf.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/10-doc2vec.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/10-text-minning-gov-report.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/10-word2vec.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/11-2-emotion-dict.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/11-3-NRC-Chinese-dict.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/11-3-textblob.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/11-4-sentiment-classifier.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/11-5-LIWC.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/12-topic-models-update.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/13-recsys-intro-surprise.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/13-recsys-intro.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/14-millionsong.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/14-movielens.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/15-network-science-intro.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/16-network-science-models.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/17-networkx.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/18-02-network-diffusion.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/18-03-network-epidemics.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/18-04-seir-hcd-model.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/18-network-ecomplexity.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/18-network-ergm-siena.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/19-visualization-datapane.ipynb
https://nbviewer.org/format/slides/github/chengjun/mybook/blob/main/19-visualization-pantheon.ipynb
RISE: “Live” Reveal.js Jupyter/IPython Slideshow Extension#
Installation#
Downnload from damianavila/RISE
open your teminal, cd to the RISE folder, e.g.,
To install this nbextension, simply run
from the RISE repository.
In the notebook toolbar, a new button (“Enter/Exit Live Reveal Slideshow”) will be available.
The notebook toolbar also contains a “Cell Toolbar” dropdown menu that gives you access to metadata for each cell. If you select the Slideshow preset, you will see in the right corner of each cell a little box where you can select the cell type (similar as for the static reveal slides with nbconvert).
cd /github/RISE/#
python setup.py install#
将ipynb文件转为slides.html#
download the reveal.js from Github hakimel/reveal.js
generate html using the following code
put the generated html into the reveal.js folder
open the html using chrome
chengjuns-MacBook-Pro:~ chengjun$ cd github/cjc/code/
chengjuns-MacBook-Pro:code chengjun$ jupyter nbconvert slides.ipynb --to slides --post serve
批量生成slides.html¶#
chengjuns-MacBook-Pro:~ chengjun$ cd github/cjc/code/
chengjuns-MacBook-Pro:code chengjun$ jupyter nbconvert *.ipynb --to slides
数学公式#
\(E = MC^2\)
%%latex
\begin{align}
a = \frac{1}{2}\\
\end{align}
程序代码#
print 'hello world'
hello world
for i in range(10):
print i
0
1
2
3
4
5
6
7
8
9
# get a list of all the available magics
% lsmagic
Available line magics:
%alias %alias_magic %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %install_default_config %install_ext %install_profiles %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
Available cell magics:
%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%latex %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile
Automagic is ON, % prefix IS NOT needed for line magics.
% env
# to list your environment variables.
{'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.Cti3IOL0XG/Render',
'CLICOLOR': '1',
'DISPLAY': '/private/tmp/com.apple.launchd.GQAU1RS6KM/org.macosforge.xquartz:0',
'GIT_PAGER': 'cat',
'HOME': '/Users/chengjun',
'JPY_PARENT_PID': '84860',
'LANG': 'en_US.UTF-8',
'LC_ALL': 'en_US.UTF-8',
'LC_CTYPE': 'UTF-8',
'LOGNAME': 'chengjun',
'PAGER': 'cat',
'PATH': '/Users/chengjun/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin',
'PWD': '/Users/chengjun',
'SECURITYSESSIONID': '186a5',
'SHELL': '/bin/bash',
'SHLVL': '2',
'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.VNCcz4m0az/Listeners',
'TERM': 'xterm-color',
'TERM_PROGRAM': 'Apple_Terminal',
'TERM_PROGRAM_VERSION': '343',
'TERM_SESSION_ID': 'FDFD985A-CDD6-415E-A3B0-E8A2A05CC9B4',
'TMPDIR': '/var/folders/l6/ntr5b4610hx38gy0_2xp7ngh0000gn/T/',
'USER': 'chengjun',
'XPC_FLAGS': '0x0',
'XPC_SERVICE_NAME': '0',
'_': '/Users/chengjun/anaconda/python.app/Contents/MacOS/python',
'__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0'}
%prun
%time range(10)
CPU times: user 11 µs, sys: 9 µs, total: 20 µs
Wall time: 21 µs
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
%timeit range(100)
The slowest run took 295.47 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 748 ns per loop
!: to run a shell command. E.g., ! pip freeze | grep pandas to see what version of pandas is installed.
! cd /Users/chengjun/github/
% matplotlib inline
# to show matplotlib plots inline the notebook.
import matplotlib.pyplot as plt
plt.plot(range(10), range(10), 'r-o')
plt.show()