小 Tips:
- 在
C:\Windows\Fonts
目录下找到Mircosoft YaHei UI
字体,然后复制到[你的Python安装路径]/Lib/site-packages/matplotlib/mpl-data/fonts/ttf
目录下即可解决Matplotlib
中文乱码的问题。 - Jupyter Notebook的27个秘诀,技巧和快捷键
下面是在 Jupyter Notebook 的 Markdown 模式:
1 字体、颜色、字号
Markdown 全篇是统一使用黑色微软雅黑字体,字号默认为 \(3\),而 HTML 却可以像 Word 那样灵活,引入大量字体包、颜色和字号,例如在 Markdown:
Hello world
- <font face="黑体"> 黑体: Hello world </font>
- <font face="STCAIYUN"> STCAIYUN: hello world </font>
- <font face="Terminal"> Terminal: Hello world </font>
- <font face="Consolas"> Consolas: Hello world </font>
- <font face="Consolas" size=3 color=#DC143C> Consolas,2,#DC143C: Hello world </font>
- <font face="Consolas" size=4 color=(220, 20, 60)> Consolas,2,(220, 20, 60): Hello world </font>
- <font face="Consolas" size=5 color=Crimson> Consolas,2,Crimson: Hello world </font>
- <font face="Consolas" size=7 color=#0099ff> Consolas,2,Crimson: Hello world </font>
展示如下:
Hello world
- 黑体: Hello world
- STCAIYUN: hello world
- Terminal: Hello world
- Consolas: Hello world
- Consolas,2,#DC143C: Hello world
- <font face="Consolas" size=4 color=(220, 20, 60)> Consolas,2,(220, 20, 60): Hello world
- Consolas,2,Crimson: Hello world
- Consolas,2,Crimson: Hello world
font
主要包含三个参数:字体(face
),字号(size
)和颜色(color
),顺序可调,也可缺省。
-
size
的可选范围为1-7
,小于 \(1\) 的数值等价于 \(1\),超过\(7\)的数值等价于\(7\)); -
color
的赋值既可以使用颜色名,例如Blue
,Black
,Crimson
等,也可以使用十六进制的颜色值#0000FF
,#000000
,#DC143C
等,如果想了解更多,可以阅读博客:CSDN-markdown编辑器语法——字体、字号与颜色。
2 数学字符及公式
再来看数学字符及公式,MarkDown 中使用标识符 $$
和 $$$$
即可表示引入 LaTeX 语法,前者使用时不换行,即在所使用位置使用 LaTeX 的格式,后者会换行后居中,例如:
$$
f(x;\mu,\sigma^2) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2 } \tag{1}
$$
where $\mu$ is the mean value, $\sigma^2$ is standard deviation.
展示如下:
\[f(x;\mu,\sigma^2) = \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2 } \tag{1} \]
where \(\mu\) is the mean value, \(\sigma^2\)
一些基本的LaTeX公式命令可参考:Markdown公式(二)
下面说下矩阵和表达式:
$$
\left[ \begin{matrix}
b_{1}&c_{1}& & & &0 \\
a_{2}&b_{2}&c_{2}& & & \\
&a_{3}&b_{3}&\ddots& & \\
& &\ddots&\ddots&c_{n-1} & \\
0& & & &a_{n}&b_{n}
\end{matrix}\right]
\left[ \begin{matrix}
x_{1} \\
x_{2} \\
x_{3} \\
\vdots\\
x_{n}
\end{matrix}\right] =
\left[ \begin{matrix}
d_{1} \\
d_{2} \\
d_{3} \\
\vdots\\
d_{n}
\end{matrix}\right]
\tag{2}
$$
$$ c'_i =
\begin{cases}
\begin{array}{lcl}
\cfrac{c_i}{b_i} & & ; i = 1 \\
\cfrac{c_i}{b_i - a_i c'_{i - 1}} & & ; i = 2, 3, \dots, n-1 \\
\end{array}
\end{cases}
\tag{3}$$
$$
展示如下
\[\left[ \begin{matrix} b_{1}&c_{1}& & & &0 \\ a_{2}&b_{2}&c_{2}& & & \\ &a_{3}&b_{3}&\ddots& & \\ & &\ddots&\ddots&c_{n-1} & \\ 0& & & &a_{n}&b_{n} \end{matrix}\right] \left[ \begin{matrix} x_{1} \\ x_{2} \\ x_{3} \\ \vdots\\ x_{n} \end{matrix}\right] = \left[ \begin{matrix} d_{1} \\ d_{2} \\ d_{3} \\ \vdots\\ d_{n} \end{matrix}\right] \tag{2} \]
\[ c'_i = \begin{cases} \begin{array}{lcl} \cfrac{c_i}{b_i} & & ; i = 1 \\ \cfrac{c_i}{b_i - a_i c'_{i - 1}} & & ; i = 2, 3, \dots, n-1 \\ \end{array} \end{cases} \tag{3} \]
3 图片排版
MarkDown 图片大小问题
引用自
MarkDown里显示图片的方式可以引入 HTML 方法:
直接以MarkDown插入图片的方法,图片就会靠在左侧,大小也不由自己决定:

固定图片显示大小:
<img src="https://s4.51cto.com/images/blog/202205/28012327_6291090f01ec950411.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=" width=256 height=256 />
- 其中
src
后面接的就是图像对象,width
和height
设置的是显示图像的尺寸。
更多的操作见:图片的操作
=====================================================================================================================================
- 基于 Ipython:Jupyter Notebooks 使用新技能
- 将 GitHub 放到 notebooks
=====================================================================================================================================
探寻有趣之事!