在Jupyter中,我如何默认使用matplotlib ggplot样式?

时间:2016-04-24 00:48:23

标签: python matplotlib jupyter

在jupyter笔记本中,我可以运行

plt.style.use('ggplot')

这允许我使用ggplot样式绘制图表。如何将此默认值设置为某个配置文件?

1 个答案:

答案 0 :(得分:5)

一种方法是使用IPython的启动文件为所有IPython会话运行任意脚本。 为此,您需要将file.py放入<user-home-dir>/.ipython/profile_default/startup文件夹中。 这个文件可以有这个代码,它将在IPython启动时执行:

import matplotlib.pyplot as plt
plt.style.use('ggplot')

另一种方法是使用您可以获得的matplotlibrc设置修改ggplot

plt.style.library['ggplot']

将输出:

RcParams({u'axes.axisbelow': True,
          u'axes.edgecolor': u'white',
          u'axes.facecolor': u'#E5E5E5',
          u'axes.grid': True,
          u'axes.labelcolor': u'#555555',
          u'axes.labelsize': u'large',
          u'axes.linewidth': 1.0,
          u'axes.prop_cycle': cycler(u'color', [u'#E24A33', u'#348ABD', u'#988ED5', u'#777777', u'#FBC15E', u'#8EBA42', u'#FFB5B8']),
          u'axes.titlesize': u'x-large',
          u'figure.edgecolor': u'0.50',
          u'figure.facecolor': u'white',
          u'font.size': 10.0,
          u'grid.color': u'white',
          u'grid.linestyle': u'-',
          u'patch.antialiased': True,
          u'patch.edgecolor': u'#EEEEEE',
          u'patch.facecolor': u'#348ABD',
          u'patch.linewidth': 0.5,
          u'xtick.color': u'#555555',
          u'xtick.direction': u'out',
          u'ytick.color': u'#555555',
          u'ytick.direction': u'out'})    

最后在key : value中粘贴这些行(matplotlibrc部分)会使ggplot样式默认生效。