【问题标题】:Seaborn barplot with axes that contain NaN带有包含 NaN 的轴的 Seaborn 条形图
【发布时间】:2020-07-21 03:17:02
【问题描述】:

我有一个包含如下列的数据框:

Electronics   Answers
Smartphone    Right
Computer      Right
Smartphone    Wrong
Smartphone    Wrong

我想要的是用 seaborn 制作一个条形图,其中 y 轴是电子设备,x 是答案。当我尝试将其插入时

ax = sns.barplot(x='answers', y='electronics', fill ='electronics', data=df)

但我得到 ValueError:xy 变量似乎都不是数字。

如何绘制 x 轴有两列的图,一列代表错误,一列代表正确,而 y 轴是每列中使用的电子设备?

感谢您的帮助。

【问题讨论】:

    标签: python seaborn


    【解决方案1】:
    import seaborn as sns
    import pandas as pd
    import matplotlib.pyplot as plt
    
    data = {'Electronics': ['Smartphone', 'Computer', 'Smartphone', 'Smartphone'],
            'Answers': ['Right', 'Right', 'Wrong', 'Wrong']}
    
    df = pd.DataFrame(data)
    
    p = sns.countplot(x='Answers', data=df, hue='Electronics')
    

    【讨论】:

      猜你喜欢
      • 2019-01-23
      • 2020-08-17
      • 2019-02-18
      • 2019-07-23
      • 2017-11-05
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多