安装jupyter notebook
- 先安装好python3
- 安装jupyter notebook ,命令行窗口中 pip3 install jupyter
- 启动jupyter notebookr
- 打开CMD命令窗口
- 输入: jupyter notebook
修改主题
- 安装主题
- pip install jupyterthemes
- pip install jupyterlab_legos_ui
- 查看已经安装的主题
- !jt -l # 列出已经安装的主题
- 结果:[chesterish,grade3,gruvboxd,gruvboxl,monokai,oceans16,onedork,solarizedd,solarizedl]
- 切换主题并设置特性
- jt -t gruvboxd # -t 后面的是要切换的新主题名称
- jt的参数表
- 重置主题至默认主题
- jt -r
参数1 |
功能 |
参数2 |
功能 |
-f |
代码字体 |
-fs |
代码字号 |
-nf |
notebook字体 |
-nfs |
notebook字号 |
-tf |
Text/MD Cell字体 |
-tfs |
Text/MD Cell字号 |
-dfs |
pandas DF字号 |
-ofs |
Output Area 字号 |
-cellw |
cell的宽度 |
-dfonts |
强制默认字体 |
-lineh |
行高 |
-l |
列出已经安装的主题 |
-r |
恢复默认主题 |
-t *** |
切换主题***:新主题名称 |
-T |
显示工具栏 |
-N |
显示名称和徽标 |
jt函数的使用
Task exception was never retrieved
future: <Task finished name='Task-12' coro=<ScriptMagics.shebang.`<locals>`._handle_stream() done, defined at C:\Python310\lib\site-packages\IPython\core\magics\script.py:211> exception=UnicodeDecodeError('utf-8', b'Microsoft Windows [\xb0\xe6\xb1\xbe 10.0.22000.556]\r\n', 19, 20, 'invalid start byte')>
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\IPython\core\magics\script.py", line 213, in _handle_stream
line = (await stream.readline()).decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 19: invalid start byte
查看已经安装的主题
Available Themes:
chesterish
grade3
gruvboxd
gruvboxl
monokai
oceans16
onedork
solarizedd
solarizedl
切换新主题
1
| !jt - t grade3 - cellw 91 % -lineh 130 - f source - fs 115 - tf ptserif - tfs 13 - nf ptsans - nfs 9 - ofs 9 - TN
|
jt -t 参数 |
功能描述 |
grade3 |
切换新主题grade3 |
-cellw 100% |
调整单元格的宽度,占屏幕的比例 |
-lineh 120 |
单元格的高度 |
-f fira -fs 115 |
设置代码字体为Fira字体大小为11.5pt |
-tf merriserif -tfs 10 |
设置makedown字体和大小 |
-nf ptsans -nfs 13 |
设置notebook(界面)字体、字体大小,实际就是菜单栏字体 |
-m 200 |
页面上的容器边距 |
-cursc r -cursw 5 |
设置光标的颜色为红色,宽度为5 |
-of *** -ofs 14 |
输出区的字形和大小(14) |
代码的字体(等宽字体):-f 参数
anka
anonymous
aurulent
bitstream
bpmono
code
consolamono
cousine
dejavu
droidmono
fira
firacode
generic
hack
hasklig
inconsolata
inputmono
iosevka
liberation
meslo
office
oxygen
roboto
saxmono
source
sourcemed
ptmono
ubuntu
Notebook 、Text/MD 单元格的字体(无衬线字体):-nf/-tf 参数
opensans
droidsans
exosans
latosans
ptsans
robotosans
sourcesans
Notebook 、Text/MD 单元格的字体(衬线字体):-nf/-tf 参数
loraserif
ptserif
georgiaserif
cardoserif
crimsonserif
ebserif
merriserif
neutonserif
goudyserif
安装插件
- 安装nbextensions
- 了解插件包的功能;
- 大部分插件只需要在nbextensions 界面勾选即可,部分需要pip 安装
<b>
limit_output extension: Maximum message size of 10000 exceeded with 10114 characters</b>
|
插件 |
功能 |
0 |
Autopep8 |
美化代码 |
1 |
Hinterland |
代码提示和补全 |
2 |
ExecuteTime |
运行时间和耗时 |
3 |
variable inspector |
变量监视 |
4 |
zenmode |
不显示菜单栏 |
5 |
code folding |
代码折叠 |
6 |
Collapsible headings |
标题折叠 |
7 |
Skip-traceback |
跳过报错的过程 |
8 |
Snippets |
插入常用代码片 |
9 |
Slideshow |
幻灯片放映 |
10 |
Jupyter Widgets |
魔法工具包 |
11 |
Table of Contents |
生成目录 |
输出其他类型代码
- 输入 %lsmagic 可以获得Magic操作符的列表
- 输入 %cmdname? 可以查看命令信息
- 输出HTML: %%html
- 输出cmd:%%cmd
- 输出LATEX:%%latex
- 嵌入链接:
- from IPython.display import IFrame
- IFrame(‘url’, width=800, height=450)
- 嵌入PDF:
- from IPython.display import IFrame
- IFrame(‘.\DR153test.pdf’, width=800, height=800)
- 运行python文件 .py
- %run xxx.py 按Ctrl+Enter后执行
Output:
Available line magics:
%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %conda %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %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 %%cmd %%debug %%file %%html %%javascript %%js %%latex %%markdown %%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.
Task exception was never retrieved
future: <Task finished name='Task-7' coro=<ScriptMagics.shebang.`<locals>`._handle_stream() done, defined at C:\Python310\lib\site-packages\IPython\core\magics\script.py:211> exception=UnicodeDecodeError('utf-8', b'Microsoft Windows [\xb0\xe6\xb1\xbe 10.0.22000.556]\r\n', 19, 20, 'invalid start byte')>
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\IPython\core\magics\script.py", line 213, in _handle_stream
line = (await stream.readline()).decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 19: invalid start byte
嵌入链接
1 2 3 4 5
| from IPython.display import IFrame
IFrame('https://pandas.pydata.org/pandas-docs/stable/reference/groupby.html', width=800, height=800)
|
Output:
显示图片
1 2 3 4
| import os from IPython.display import Image, IFrame
Image('./1.webp', width='25%')
|
Output:
1 2 3 4
| import os from IPython.display import Image, IFrame
Image('./1.webp', retina=True)
|
Output:
显示pdf
1 2 3 4 5
| import os from IPython.display import Image, IFrame
IFrame('./2.pdf', width='80%', height='800px')
|
Output:
更新软件包
1
| !pip3 install --upgrade pip
|