Легенда для Matplotlib - PullRequest
       4

Легенда для Matplotlib

0 голосов
/ 17 июня 2020

Я хочу, чтобы моя легенда показывала метки из обоих подзаголовков, но отображалась только одна. Я пробовал использовать plt и ax, но до сих пор могу отобразить только один ярлык. Любая помощь будет принята с благодарностью!

Вот мой код

for i, j, k in zip(x,elements,range(len(data))):
    
    
   # print(i)      # assign the column number for each element to the relevant statistic
    i = x[0] 
    #print(i[0])
    #print(j)
    #print(k)      
    mean_col = (i[0])
    SD_col = i[1]
    Min_col = i[2]
    Percentile_5_col = i[3]
    #Percentile_50_col = i[4]
    Percentile_95_col = i[5]
    Max_col = i[6]    
    # make a figure for each element
    #fig = plt.figure()        
    fig, ax0 = plt.subplots(sharex=True)  
    ax1 = ax0.twinx()
    plt.title('Mass Contribution of %s to Pit Lake from HARA' %(j), fontsize=16)
    date = data['Date']
    Pit_Vol = PitVolume['Mean']
    # assign the columns to make the data
    mean = data.iloc[:,mean_col]     
   # SD = data.iloc[:, SD_col]
    Min = data.iloc[:,Min_col]
    Percentile_5 = data.iloc[:,Percentile_5_col]
    #Percentile_50 = data.iloc[:,Percentile_50_col]
    Percentile_95 = data.iloc[:,Percentile_95_col]
    Max = data.iloc[:,Max_col]  
    
    ax0.plot(date, Max, label = 'Maximum', color='green')  
    ax0.plot(date, Percentile_95, label = '95th percentile', color='grey')
    ax0.plot(date, mean, label = 'Mean', color='black')   
   # plt.plot(date, SD, label = 'SD', color='g')
    ax0.plot(date, Min, label = 'Minimum', color='green')
    ax0.plot(date, Percentile_5, label = '5th percentile', color='grey')
    ax1.plot(date, Pit_Vol, label = 'Pit Volume', color='cyan', linestyle='--')  
   # plt.plot(date, Percentile_50, label = '50th per') 
    plt.xlabel('Year',fontsize=14)
    plt.ylabel('Mass Contribution from HARA (%)',fontsize=14)
    plt.yticks(fontsize=12)
    plt.xticks(fontsize=12)
    plt.xlabel
   # plt.legend(loc=1)
    #ax0.legend(loc=1)
    #ax1.legend()
    plt.legend((mean, Min, Percentile_5, Percentile_95, Max, Pit_Vol), ('Mean', 'Minimum', '5th Percentile', '95th Percentile', 'Maximum', 'Pit Volume'))
...