gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:55 24 4
gpt4 key购买 nike

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

plt.style.use('ggplot')

这让我可以使用 ggplot 样式来绘图。我怎样才能使这个默认值,比如说,把它放在某个配置文件中?

最佳答案

一种方法 是使用 IPython 的启动文件为所有 IPython session 运行任意脚本。为此,您需要将任何 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 样式默认生效。

关于python - 在 Jupyter 中,如何默认使用 matplotlib ggplot 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36818080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com