专栏名称: 编程派
Python程序员都在看的公众号,跟着编程派一起学习Python,看最新国外教程和资源!
目录
相关文章推荐
51好读  ›  专栏  ›  编程派

装扮你的 Jupyter Notebook

编程派  · 公众号  · Python  · 2017-06-09 11:39

正文

请到「今天看啥」查看全文


"import numpy as np" ,

  • "import scipy.stats as spstats" ,

  • "import scipy as sp" ,

  • "import matplotlib.pyplot as plt"

  • ]

  • 当然,也可以更多。但这样可能会影响初始化 notebook 和 ipython shell 的速度,这个请大家自己权衡。

    matplotlib 显示中文

    此外,单独拎 matplotlib 出来的另一个原因是, matplotlib 还有一个中文显示的问题。

    首先,解决 编码问题

    python 2.7 .* 的解决方案是,在配置中加入:

    1. import seaborn as sns

    2. import sys# print sys.getdefaultencoding()# ipython notebook 中默认是 ascii 编码

    3. reload(sys)

    4. sys.setdefaultencoding('utf8')

    python 3. * 出于某些原因,不建议通过 sys 模块修改编码,原因参见 这里。

    解决方案是,在 shell 的配置中重新设置配置变量( bash 的话设置文件 . bashrc zsh 则设置文件 . zshrc )。方法是末尾添加:

    1. export PYTHONIOENCODING="utf8"

    当然另一个方法是在启动 notebook 时使用

    1. PYTHONIOENCODING="utf8" & jupyter notebook

    第二个是 修改 matplotlib 的默认字体

    首先我们来看可以使用的字体

    1. import matplotlib.font_manager

    2. fonts = matplotlib.font_manager.findSystemFonts()

    3. l = []

    4. for f in fonts:

    5.    try:

    6.        font =matplotlib.font_manager.FontProperties(fname=f)

    7.        #print(font.get_family())

    8.        l.append((f, font.get_name(),







    请到「今天看啥」查看全文