【问题标题】:Seaborn distribution plot line graph shows ringingSeaborn 分布图折线图显示振铃
【发布时间】:2020-06-21 22:43:57
【问题描述】:

在我的带有代码的 Seaborn 图表中

import seaborn as sns
df['hour'] = df['time']/3600
plt.figure(figsize=(30,10))               
plt.gcf().subplots_adjust(left = 0.3)
g = sns.distplot(df['hour'], axlabel = 'No. Of Hours', label = 'Frequency')

分布图附带的折线图看起来很奇怪,因为它为每个条形显示一个峰值,并在分布图的右尾显示出增加的趋势,那里几乎没有数据。这张图正确吗?如果没有,它有什么问题,我该如何纠正?这是图表:

【问题讨论】:

    标签: python matplotlib plot seaborn google-colaboratory


    【解决方案1】:

    此问题报告于http://github.com/mwaskom/seaborn/issues/1590

    这与 statsmodels 包使用的 KDE 算法有关。您可以通过添加以下行来强制 seaborn 使用 scipy 的算法:

    sns.distributions._has_statsmodels = False
    

    这是一个重现问题的简短 sn-p:

    import seaborn as sns
    import pandas as pd
    import matplotlib.pyplot as plt
    df = pd.DataFrame({
        'hour': [1] + 100 * [2] + [10]
    })
    plt.figure(figsize=(30,10))               
    plt.gcf().subplots_adjust(left = 0.3)
    g = sns.distplot(df['hour'], axlabel = 'No. Of Hours', label = 'Frequency')
    

    如果你强制它不使用 statsmodels,结果如下:

    sns.distributions._has_statsmodels = False
    plt.figure(figsize=(30,10))               
    plt.gcf().subplots_adjust(left = 0.3)
    g = sns.distplot(df['hour'], axlabel = 'No. Of Hours', label = 'Frequency')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2022-01-20
      • 2015-04-08
      相关资源
      最近更新 更多