gpt4 book ai didi

python - Python中的ggplot样式

转载 作者:IT老高 更新时间:2023-10-28 20:21:25 24 4
gpt4 key购买 nike

当我查看 plotting style in the Pandas documentation ,图看起来与默认图不同。它似乎模仿了 ggplot 的“外观和感觉”。

seaborn's package 相同.

如何加载该样式? (即使我不使用笔记本?)

最佳答案

更新:如果你有 matplotlib >= 1.4,有一个新的 style 模块,它默认具有 ggplot 风格。要激活它,请使用:

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

要查看所有可用的样式,您可以查看plt.style.available


同样,对于 seaborn 样式,您可以这样做:

plt.style.use('seaborn-white')

或者,您可以使用 seaborn 自己的机器来设置样式:

import seaborn as sns
sns.set()

set() 函数有更多选项来选择特定样式(参见 docs )。请注意,seaborn 之前在导入时会自动执行上述操作,但在最新版本 (>= 0.8) 中不再是这种情况。


如果你真的想要在 Python 中使用类似 ggplot 的语法(而不仅仅是样式),请查看 plotnine包,是Python中图形实现的语法,语法与R的ggplot2非常相似。


注意:提到的旧答案 pd.options.display.mpl_style = 'default'
。然而,这在 pandas 中已被弃用,取而代之的是 matplotlib 使用 plt.style(..) 的样式,同时此功能甚至从 pandas 中删除。

关于python - Python中的ggplot样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22543208/

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