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

如何在matplotlib boxplot中为每个x显示两个数字?

  •  0
  • aman  · 技术社区  · 7 年前

    我试着给每个人看两个数字 x org_data , holiday_false holiday_true ). 请帮忙。

    data.csv:

    weekday | holiday | casual | registered
    ---------------------------------------
       0         1        500       153
       2         0        412       654
       6         1        846       113
       2         0        456       121
       3         0        124       654
      ...       ...       ...       ...
      ...       ...       ...       ...
    

    code:

    import numpy as np
    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    import os
    plt.style.use('seaborn-notebook')
    %matplotlib inline
    
    fig, axes = plt.subplots(figsize=(16, 7))
    org_data = pd.read_csv("data.csv")
    
    holiday_false = org_data[(org_data["holiday"] == 0) & (org_data["weekday"] != 0) & (org_data["weekday"] != 6)]
    holiday_true = org_data[(org_data["holiday"] == 1) | (org_data["weekday"] == 0) | (org_data["weekday"] == 6)]
    
    ax1 = plt.subplot(121)
    sns.boxplot(x=org_data["weekday"], y=holiday_false["casual"], color="orange")
    sns.boxplot(x=org_data["weekday"], y=holiday_true["casual"], color="skyblue")
    ax1.set_title("Nuber of Casual Users on Holidays and Non-Holidays")
    ax1.set_xlabel("Days")
    ax1.set_ylabel("Number of Casual Users")
    
    ax2 = plt.subplot(122)
    sns.boxplot(x=org_data["weekday"], y=holiday_false["registered"], width=0.50, color="orange")
    sns.boxplot(x=org_data["weekday"], y=holiday_true["registered"], width=0.50, color="skyblue")
    ax2.set_title("Number of Registered Users on Holidays and Non-Holidays")
    ax2.set_xlabel("Days")
    ax2.set_ylabel("Number of Registered Users")
    
    plt.show()
    

    the type of chart I get:

    enter image description here

    the chart I want:

    enter image description here

    0 回复  |  直到 7 年前