代码之家  ›  专栏  ›  技术社区  ›  Rocketq

如何用箱线图绘制relplot,然后只有seaborn中指定的频率

  •  1
  • Rocketq  · 技术社区  · 6 年前

    让我们有这样的数据:

    import pandas as pd
    import seaborn as sns
    data = np.array([[5.2, 500, 1], [7.2, 450, 1],[6.2, 350, 1],[4.6, 400,1 ],[5.9, 212,1], [6.2, 350, 2],[4.6, 400,2 ],[5.9, 212,2]])
    df = pd.DataFrame({'val':data[:,0],'size':data[:,1], 'time':data[:,2]})
    

    enter image description here

    val -实际平均值,由中指定大小的数据集计算得出 size

    绘制箱线图:

    ax = sns.boxplot (x = 'time', y="val", data=df)
    ax = sns.swarmplot(x = 'time', y="val", data=df, color=".25", size = df.size )
    

    enter image description here

    瓦尔 除以 大小 对于每个 time

    relplot 帮助以适当的大小绘制点的大小,但如何绘制真正的箱线图:

    ax = sns.relplot(x = 'time', y="val",  size="size",dashes = True,
                sizes=(40, 400), alpha=.5, palette="muted",
                height=6, data=df)
    

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   Diziet Asahi    6 年前

    我没有Seaborn0.9.0来直接测试这个,但是从我读到的 from the documentation sns.relplot() 返回一个 FacetGrid sns.boxplot is an axes level function

    g = sns.relplot(x = 'time', y="val", data=df, size="size")
    ax = sns.boxplot (x = 'time', y="val", data=df, ax=g.axes[0,0])  # <-