Jupyter Notebook 使用小技巧


小 Tips:

  1. C:\Windows\Fonts目錄下找到Mircosoft YaHei UI字體,然后復制到[你的Python安裝路徑]/Lib/site-packages/matplotlib/mpl-data/fonts/ttf目錄下即可解決Matplotlib中文亂碼的問題。
  2. 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的賦值既可以使用顏色名,例如BlueBlackCrimson等,也可以使用十六進制的顏色值 #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\) is standard deviation.

一些基本的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 圖片大小問題

引用自:文章鏈接: http://blog.csdn.net/yhl_leo/article/details/50099843

MarkDown里顯示圖片的方式可以引入 HTML 方法:

直接以MarkDown插入圖片的方法,圖片就會靠在左側,大小也不由自己決定:

![雷姆](http://static.zybuluo.com/xinet/dk25o6spbuvf486y2kh8b7oq/%E9%9B%B7%E5%A7%86.PNG)

雷姆

固定圖片顯示大小:

<img src="http://static.zybuluo.com/xinet/dk25o6spbuvf486y2kh8b7oq/%E9%9B%B7%E5%A7%86.PNG" width=256 height=256 />
  • 其中 src 后面接的就是圖像對象,widthheight 設置的是顯示圖像的尺寸。

更多的操作見:圖片的操作

=====================================================================================================================================

=====================================================================================================================================


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM