【问题标题】:Barplot in seaborn with height based on an arrayseaborn中的条形图,高度基于数组
【发布时间】:2020-05-26 11:40:56
【问题描述】:

设置y=[0.7,0.2,0.1,0.05]x=[1,2,3,4],如何在seaborn 中创建条形图/条形图,其中高度由y 指定,用于x 中给出的标签,即第一个条形的高度为0.7,第二个条形高度为 0.2 等,就像 matplotlib

plt.bar(x=[1,2,3,4],height=y)

【问题讨论】:

    标签: python bar-chart seaborn


    【解决方案1】:

    您可以直接将其作为 x 和 y 传递,无需 data.frame:

    import seaborn as sns
    sns.set()
    sns.barplot(x=[1,2,3,4],y=[0.7,0.2,0.1,0.05])
    

    如果您不希望栏使用不同的颜色,请执行以下操作:

    sns.barplot(x=[1,2,3,4],y=[0.7,0.2,0.1,0.05],color="b")
    

    【讨论】:

    • 我确实试过了,但它给我一个错误,我不能同时使用“x”和“y”,但现在它可以工作了!
    猜你喜欢
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 2016-02-06
    • 2015-12-08
    • 1970-01-01
    相关资源
    最近更新 更多