问题描述
当我查看Pandas文档中的时,这些图表看起来与默认的。它似乎模仿了ggplot的外观和感觉。
When I look at the plotting style in the Pandas documentation, the plots look different from the default one. It seems to mimic the ggplot "look and feel".
与。
如何加载该样式? (即使我没有使用笔记本?)
How can I load that style? (even if I am not using a notebook?)
推荐答案
更新:如果你有matplotlib> = 1.4,有一个新的样式
模块,默认情况下具有 ggplot
样式。要激活它,请使用:
Update: If you have matplotlib >= 1.4, there is a new style
module which has a ggplot
style by default. To activate this, use:
from matplotlib import pyplot as plt
plt.style.use('ggplot')
建议通过pandas选项进行样式设置,如下所述(也用于熊猫) docs now。)
This is recommended above the styling through the pandas options as explained below (and is also used in the pandas docs now).
对于pandas,请使用:
For pandas, use:
pd.options.display.mpl_style = 'default'
和这将为matplotlib数字提供'ggplot-like'样式(请注意,该名称有点令人困惑,因为默认情况下未启用此功能,实际上应该将其添加到文档中)。
and this will give you the 'ggplot-like' style for matplotlib figures (Note that the name is a bit confusing as this is not enabled by default, and this should actually be added to the docs).
对于seaborn,正如Paul H评论的那样,足以导入seaborn
For seaborn, as Paul H commented, it is enough to import seaborn
顺便说一下,如果你真的想要ggplot中的ggplot和ggplot语法(而不仅仅是ggplot样式),那么还有一个基于pandas的 python ggplot库 :
By the way, if you really want something like ggplot in python with ggplot syntax (and not only ggplot-like style), there is also a python ggplot library based on pandas: https://github.com/yhat/ggplot/
这篇关于Python中的ggplot样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!