小编Wal*_*ter的帖子

为什么Seaborn调色板不能用于Pandas条形图?

在线Jupyter笔记本演示代码并显示颜色差异,请访问:https://anaconda.org/walter/pandas_seaborn_color/notebook

当我使用Pandas数据帧方法制作条形图时,颜色是错误的.Seaborn改善了matplotlib的调色板.matplotlib的所有图表都会自动使用新的Seaborn调色板.但是,Pandas数据帧的条形图恢复为非Seaborn颜色.此行为不一致,因为来自Pandas数据帧的线图确实使用了Seaborn颜色.这使我的情节看起来有不同的风格,即使我将Pandas用于我的所有情节.

如何在获得一致的Seaborn调色板的同时使用Pandas方法进行绘图?

我在python 2.7.11中使用conda环境运行它,只需要这个代码的必要包(pandas,matplotlib和seaborn).

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame({'y':[5,7,3,8]})

# matplotlib figure correctly uses Seaborn color palette
plt.figure()
plt.bar(df.index, df['y'])
plt.show()

# pandas bar plot reverts to default matplotlib color palette
df.plot(kind='bar')
plt.show()

# pandas line plots correctly use seaborn color palette 
df.plot()
plt.show()
Run Code Online (Sandbox Code Playgroud)

matplotlib pandas seaborn

6
推荐指数
1
解决办法
5225
查看次数

标签 统计

matplotlib ×1

pandas ×1

seaborn ×1