【问题标题】:Is it okay to use the barplot function without specifying `order?可以在不指定`order的情况下使用barplot函数吗?
【发布时间】:2019-11-24 18:13:54
【问题描述】:

我正在基于这个 Kaggle kernel 处理泰坦尼克号数据集。在我尝试使用 barplot 函数的部分,它给了我一条警告消息 UserWarning: Using the barplot function without specifying order 可能会产生不正确的绘图。

我应该担心吗?

我已尝试指定 order 参数和 hue_order。

grid = sns.FacetGrid(train_df, col='Embarked', row='Survived', height=2.2, aspect=1.6)
grid.map(sns.barplot, 'Sex', 'Fare', alpha=0.5, ci=None, order=[1,2,3], hue_order=['Embarked', 'Survived'])
grid.add_legend()

当我指定 order 和 hue_order 时,它给了我空的条形图。 empty barplots

但是,当我取出 order 和 hue_order 时,它确实给了我带有此警告消息的图:

C:\Users\user\Anaconda3\lib\site-packages\seaborn\axisgrid.py:715: UserWarning: Using the barplot function without specifying `order` is likely to produce an incorrect plot.
warnings.warn(warning)

results with error warning

有什么我应该知道的想法或提示吗?提前致谢!

【问题讨论】:

  • 我无法在您的代码中发现任何错误。您是否已经尝试过plt.show() 命令?有时它可能会影响结果....
  • @cyber-math 我做了,它给了我结果,但仍然有相同的警告信息。

标签: python jupyter-notebook


【解决方案1】:

我不确定如何使用 sns.Facetgrid 修复警告。您可以改用 catplot 来绘制完全相同的图。

这是我的代码:

g = sns.catplot(x="Sex", y='Fare', row="Embarked",
                   col='Survived', data=train_df,kind ='bar')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多