繁体   English   中英

在Jupyter中,默认情况下如何使用matplotlib ggplot样式?

[英]In Jupyter, how can I use the matplotlib ggplot style by default?

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

plt.style.use('ggplot')

这使我可以使用ggplot样式进行绘图。 我如何通过将其放在配置文件中的某个位置来使其成为默认值?

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

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

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

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样式默认生效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM