首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Seaborn barplot color_palette不工作

Seaborn barplot color_palette不工作
EN

Stack Overflow用户
提问于 2019-07-24 23:40:28
回答 1查看 166关注 0票数 0

我看到了一种奇怪的行为,那就是海边的一块弹道。我正在使用一个脚本,我验证了它与一个数据帧一起工作。当我连接多个数据帧并使用groupby时,条形图显示为白色,即color_palette不再工作。

代码语言:javascript
复制
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.collections import PolyCollection as p
import seaborn as sns

sns.set(font_scale=1.5, style='white', context='paper')

def plot_consumers(count, df):
    print(count.groupby(['periods'], as_index=False)[
                    'consumerId'].mean().describe())
    fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
    pal = sns.color_palette('Blues_d', n_colors=1)

    sns.barplot(x='periods',
                y='consumerId',
                data=count.groupby(['periods'], as_index=False)[
                    'consumerId'].mean(),
                ax=axes[0],
                palette=pal)

    sns.lineplot(x='periods',
                 y='distance',
                 data=df.groupby(['periods'], as_index=False)[
                     'distance'].mean(),
                 legend=False,
                 ax=axes[1])

    # Axes config
    axes[0].set(ylim=(-0.05, 100.05))
    axes[0].set(ylabel='%')
    axes[0].set(xlim=(-10, 310))
    axes[0].xaxis.set_major_locator(ticker.MultipleLocator(100))
    axes[0].xaxis.set_major_formatter(ticker.ScalarFormatter())
    axes[1].set(ylabel='customer satisfaction')
    axes[1].set(ylim=(-0.05, 1.05))

    fig.tight_layout()
    plt.show()

在对count数据框进行分组后,我得到了以下内容:

代码语言:javascript
复制
          periods  consumerId
count  300.000000  300.000000
mean   149.500000   21.540741
std     86.746758    0.175113
min      0.000000   19.666667
25%     74.750000   21.555556
50%    149.500000   21.555556
75%    224.250000   21.555556
max    299.000000   23.111111

我知道正在绘制条形图,因为我将样式更改为dark,并且我可以看到白色的条形图。

如果我将柱状图改为折线图,它也可以工作。

下面是使用barplotdark样式的绘图:

下面是使用lineplotwhite样式的绘图:

EN

回答 1

Stack Overflow用户

发布于 2019-07-25 05:17:24

根据@mwaskom的说法,这个问题是因为我试图在很短的空间内容纳太多的条形图。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57186663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档