代码之家  ›  专栏  ›  技术社区  ›  Niklas E.

Seaborn对象界面:日志转换的条形图未正确绘制

  •  0
  • Niklas E.  · 技术社区  · 2 年前

    我有一个关于seaborn对象接口的快速问题。我试图简单地生成一个带有对数缩放y轴的躲避条形图。条形图渲染没有任何问题,但只要我通过 .scale(y="log") 到Plot对象,我得到错误 Ill-defined clip_path detected 并且只绘制了一条线而不是条形图。通过经典界面绘图效果良好。

    我很想继续使用对象界面,想知道这是错误还是用户错误?

    以下是示例代码和输出:

    import seaborn.objects as so
    from seaborn import axes_style
    import seaborn as sns
    import random
    
    # Generate some example dataframe
    dfl_filtered = pd.DataFrame({'Analyte Name':['group 1','group 1', 'group 2','group 2'],
                                 'Protein':['protein 1', 'protein 2', 'protein 1', 'protein 2'],
                                 'c':[4000, 90000, 6000, 200000]})
    # Plot with linear scale
    p = (
        so.Plot(dfl_filtered, x='Analyte Name', y='c', )
        .add(so.Bar(edgecolor="black"), so.Agg(), so.Dodge(), color='Protein')
        .add(so.Range(color="black"), so.Est(errorbar="se"), so.Dodge(), color='Protein')
        .label(x="", y="c [ng/mL]")
        .theme(axes_style("ticks"))
        .layout(size=(4,3))
    )
    p.show()
    
    # Plot with log scale
    p = (
        so.Plot(dfl_filtered, x='Analyte Name', y='c', )
        .add(so.Bar(edgecolor="black"), so.Agg(), so.Dodge(), color='Protein')
        .add(so.Range(color="black"), so.Est(errorbar="se"), so.Dodge(), color='Protein')
        .label(x="", y="c [ng/mL]")
        .theme(axes_style("ticks"))
        .layout(size=(4,3))
        .scale(y="log")
    )
    p.show()
    
    # Plot without the objects interface
    fig, ax = plt.subplots()
    
    sns.barplot(dfl_filtered, x='Analyte Name', y='c', hue='Protein', dodge=True)
    ax.set_yscale("log")
    fig.show()
    

    enter image description here

    Ill-defined clip_path detected. Returning None.
    Ill-defined clip_path detected. Returning None.
    Ill-defined clip_path detected. Returning None.
    Ill-defined clip_path detected. Returning None.
    

    enter image description here enter image description here

    0 回复  |  直到 2 年前