代码之家  ›  专栏  ›  技术社区  ›  Ladenkov Vladislav

Seaborn Relplots创建复制轴

  •  0
  • Ladenkov Vladislav  · 技术社区  · 7 年前

    我正在尝试创建两个情节-一个在另一个下面与希伯恩!< BR> 我的代码:

    fig,(ax1,ax2)=plt.subflots(nrows=2,sharex=true,figsize=(22,8))。
    p1=sns.relplot(x=“sns_codes”,y=“triad_quantity”,hue=“label”,data=data_2,kind=“line”,ax=ax1)
    p2=sns.relplot(x=“sns_codes”,y=“triad_quantity”,hue=“label”,data=data_2,kind=“line”,ax=ax2)
    < /代码> 
    
    

    但这将创建4个轴而不是2个!看:

    我放弃阅读这些额外的2个轴-需要帮助。
    下面是创建数据的代码:

    df='label':0:'top_5',
    1:'第一页',
    2:'赢率卡',
    4:'关闭',
    5:“Topy5”,
    6:'第一页',
    7:'赢了',
    9:'关闭',
    10:“Topy5”,
    11:'第一页',
    '报告日期':0:timestamp('2018-08-21 00:00:00'),
    1:时间戳(“2018-08-21 00:00:00”),
    2:时间戳(“2018-08-21 00:00:00”),
    4:时间戳(“2018-08-22 00:00:00”),
    5:时间戳(“2018-08-22 00:00:00”),
    6:时间戳(“2018-08-22 00:00:00”),
    7:时间戳(“2018-08-22 00:00:00”),
    9:时间戳(“2018-08-23 00:00:00”),
    10:时间戳(“2018-08-23 00:00:00”),
    11:时间戳(“2018-08-23 00:00:00”),
    'sns_codes':0:0,1:0,2:0,4:1,5:1,6:1,7:1,9:2,10:2,11:2,
    'Triad_数量':0:9,
    1:204,
    2:214,
    4:20,
    5:5,
    6:191,
    7:230,
    9:21,
    10:2,
    11:98 }
    数据_2=pd.数据帧(df)
    < /代码> <

    但这将创建4个轴而不是2个!看:

    enter image description here

    我放弃了阅读这些额外的2个轴-需要帮助。
    下面是创建数据的代码:

    df ={'label': {0: 'top_5',
      1: 'first_page',
      2: 'win_ratecard',
      4: 'switched_off',
      5: 'top_5',
      6: 'first_page',
      7: 'win_ratecard',
      9: 'switched_off',
      10: 'top_5',
      11: 'first_page'},
     'report_date': {0: Timestamp('2018-08-21 00:00:00'),
      1: Timestamp('2018-08-21 00:00:00'),
      2: Timestamp('2018-08-21 00:00:00'),
      4: Timestamp('2018-08-22 00:00:00'),
      5: Timestamp('2018-08-22 00:00:00'),
      6: Timestamp('2018-08-22 00:00:00'),
      7: Timestamp('2018-08-22 00:00:00'),
      9: Timestamp('2018-08-23 00:00:00'),
      10: Timestamp('2018-08-23 00:00:00'),
      11: Timestamp('2018-08-23 00:00:00')},
     'sns_codes': {0: 0, 1: 0, 2: 0, 4: 1, 5: 1, 6: 1, 7: 1, 9: 2, 10: 2, 11: 2},
     'triad_quantity': {0: 9,
      1: 204,
      2: 214,
      4: 20,
      5: 5,
      6: 191,
      7: 230,
      9: 21,
      10: 2,
      11: 98}}
     data_2 = pd.DataFrame(df)
    
    2 回复  |  直到 6 年前
        1
  •  3
  •   Sheldore    7 年前

    sns.relplot relplot class:FacetGrid object here ax1 ax2 p1 p2

    plt.close(p1.fig)
    plt.close(p2.fig) 
    
        2
  •  0
  •   EEE EdChum    6 年前

    figure-level axes-level

    fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, figsize=(22,8))
    p1 = sns.lineplot(x="sns_codes", y="triad_quantity", hue="label", data=data_2, kind="line", ax=ax1)
    p2 = sns.lineplot(x="sns_codes", y="triad_quantity", hue="label", data=data_2, kind="line", ax=ax2)
    

    row="a_column_on_which_your_plots_vary" seaborn tutorial