Я не могу определить, верна ли моя среднемесячная функция, и я не могу получить ежемесячное среднее значение, которое будет отображаться на графике. Когда я запускаю код, он строит график так, как будто функции среднемесячного значения даже не существует. Я хочу рассчитать среднемесячное значение из ежедневных таве (ов) и центрировать среднее значение в середине месяца. Можете ли вы решить / определить проблему с моим кодом?

Мой текущий код:

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import datetime

def ReadData(fname,Tmax,Tmin,Tave,dates, filterYear):    
    '''    
Read the temperature variation data and append four lists containing the maximum
temperatures as floats, the minimum temperatures as floats, the average
temperatures as floats, and the dates as string YYYYMMDD format.
    '''
    fileObj = open(fname,'r') # associate the fileObj variable with filename
    lineList = fileObj.readlines() # read all lines in file and returns them into a list
    fileObj.close
    nHeaderLines = 2 # number of lines to skip
    for line in range(nHeaderLines, len(lineList)): # loop over lines in the list   
        itemList = lineList[line].split() # split current line
        TMIN = float(itemList[12])
        TMAX = float(itemList[11])
        TAVE = float(itemList[10])
        dateList = int(itemList[9])        
        #Convert from file the date string to date time object
        formatedDate = datetime.datetime.strptime(str(dateList),"%Y%m%d").date()
        #Check the year condition and only select only that data for plotting
        if formatedDate.year in filterYear:        
            Tmin.append(TMIN)
            Tmax.append(TMAX)
            Tave.append(TAVE)
            dates.append(formatedDate)
    return Tmin,Tmax,Tave,dates
##################################################################

def MonthMean(Tave,dates):
    year = int(dates/10000) # convert dateList to years
    month = int((dates%10000) / 100) # convert dateList to months
    day = int(dates%100) # convert dateList to days
    # Calculate monthly mean by sum(Tave) in corresponding month and dividing by total days for that month
    for day in month:
        if 31 == int(day):
            mmonth31 = sum(Tave) / 31
        elif 30 == int(day):
            mmonth30 = sum(Tave) / 30
        elif 28 == int(day):
            mmonth28 = sum(Tave) / 28
    return mmonth31, mmonth30, mmonth28
               
def main():
    fname = 'DallasTX.txt' # initialize filename
    print('Reading file: ',fname)    
    Tmin = [] # initialize Temp list - Tmin
    Tmax = [] # initialize Temp list - Tmax
    Tave = [] # initialize Temp list - Tave
    dates = [] # initialize date list
    #Remember range is exclusive for the upper limit, So range(2010,2021,1) returns 2010 until 2020
    filterYear = range(2010,2019,1)
    #Call the ReadData() function which returns a list of min, max, Avg, Temp, date, year, month, day values
    Tmin, Tmax, Tave, dates = ReadData(fname,Tmax,Tmin,Tave,dates, filterYear) 
    dates = [datetime.datetime.strptime(str(d),"%Y-%m-%d").date() for d in dates]    
    fig, ax = plt.subplots(sharex = True)
    ax = plt.gca() 
    #Set Limit for Min and Max values temp
    plt.ylim(0,120)
    plot1 = ax.plot(dates, Tmax,'red',label='Max Temp.')
    plot2 = ax.plot(dates, Tmin,'blue',label='Min Temp.')    
    plot3 = ax.plot(dates, Tave,'black',label='Ave Temp.')   
    #Combine plots to get thelegends
    plots = plot1 + plot2 + plot3
    legends = []
    for plot in plots:
        legends.append(plot.get_label())
    #Include the legends in the plots
    ax.legend(plots, legends)    
    # format your data to desired format.
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))    
    ax.set_xlabel('Yearly trend')
    ax.set_ylabel('Temp in Farheinhite')
    ax.set_title('Annual Temperatures at Dallas Love Field (2014-2015)')
main()

Пример файла данных 'DallasTX.txt' (образец настолько, насколько я считал актуальным):

STATION           STATION_NAME                                       ELEVATION  LATITUDE   LONGITUDE  DATE     TAVG     TMAX     TMIN     
----------------- -------------------------------------------------- ---------- ---------- ---------- -------- -------- -------- -------- 
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20131231 39       55       27       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140101 49       70       35       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140102 38       43       26       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140103 38       53       28       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140104 51       70       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140105 42       60       22       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140106 24       34       15       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140107 33       48       22       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140108 41       48       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140109 46       49       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140110 57       69       47       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140111 54       69       38       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140112 56       74       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140113 60       64       45       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140114 51       66       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140115 45       56       34       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140116 50       65       40       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140117 50       55       38       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140118 49       68       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140119 49       64       33       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140120 55       73       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140121 48       54       36       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140122 43       60       31       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140123 39       45       24       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140124 27       41       17       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140125 43       67       29       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140126 56       74       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140127 44       51       25       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140128 28       36       23       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140129 31       47       19       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140130 41       58       31       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140131 60       75       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140201 57       66       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140202 37       39       30       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140203 34       44       30       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140204 41       47       38       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140205 33       38       23       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140206 21       24       17       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140207 26       32       23       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140208 37       54       31       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140209 44       48       37       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140210 35       37       30       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140211 31       35       29       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140212 38       51       30       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140213 45       67       32       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140214 56       72       44       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140215 53       69       37       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140216 60       76       48       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140217 67       75       52       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140218 61       80       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140219 66       70       61       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140220 67       74       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140221 52       66       37       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140222 61       74       49       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140223 62       71       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140224 51       57       45       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140225 51       54       42       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140226 40       43       31       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140227 40       55       28       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140228 56       83       43       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140301 64       81       52       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140302 43       71       20       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140303 23       34       16       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140304 34       50       26       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140305 42       55       34       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140306 47       55       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140307 50       67       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140308 53       55       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140309 45       63       37       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140310 58       78       43       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140311 67       81       56       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140312 57       63       45       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140313 53       69       39       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140314 59       72       48       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140315 63       67       53       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140316 51       56       42       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140317 47       61       36       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140318 61       82       49       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140319 59       66       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140320 56       72       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140321 65       80       53       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140322 64       67       51       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140323 53       59       47       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140324 53       67       41       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140325 54       64       43       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140326 53       62       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140327 65       82       58       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140328 71       82       53       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140329 60       75       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140330 63       79       49       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140331 67       81       58       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140401 73       85       65       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140402 75       83       70       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140403 77       84       60       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140404 60       68       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140405 54       56       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140406 50       53       47       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140407 53       68       47       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140408 59       71       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140409 63       81       45       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140410 72       86       59       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140411 72       83       63       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140412 74       84       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140413 71       79       64       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140414 55       64       43       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140415 49       64       37       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140416 56       69       45       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140417 58       64       51       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140418 65       78       56       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140419 68       79       57       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140420 70       81       63       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140421 69       80       62       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140422 72       84       60       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140423 74       87       61       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140424 76       84       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140425 71       83       57       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140426 73       84       63       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140427 79       92       73       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140428 76       83       65       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140429 70       76       56       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140430 60       69       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140501 60       75       46       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140502 68       82       52       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140503 71       89       50       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140504 78       94       62       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140505 77       90       63       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140506 77       88       65       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140507 77       85       70       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140508 73       77       64       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140509 75       89       65       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140510 76       87       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140511 79       89       73       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140512 77       84       59       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140513 61       69       55       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140514 62       72       53       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140515 66       83       53       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140516 71       86       57       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140517 74       82       60       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140518 74       83       64       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140519 76       86       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140520 78       87       70       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140521 78       87       69       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140522 78       88       69       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140523 77       82       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140524 78       86       72       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140525 77       87       73       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140526 76       80       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140527 71       78       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140528 74       84       66       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140529 78       90       67       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140530 79       88       70       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140531 77       88       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140601 80       90       72       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140602 82       91       75       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140603 83       91       75       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140604 84       92       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140605 83       91       75       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140606 83       91       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140607 85       95       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140608 82       87       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140609 75       80       64       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140610 76       85       67       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140611 80       95       67       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140612 80       85       72       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140613 81       89       74       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140614 82       91       74       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140615 84       93       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140616 85       94       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140617 85       94       78       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140618 85       95       77       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140619 83       95       76       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140620 85       93       77       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140621 84       89       79       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140622 77       81       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140623 77       88       69       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140624 80       92       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140625 75       86       71       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140626 78       90       72       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140627 81       92       74       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140628 83       90       77       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140629 86       94       80       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140630 86       95       77       
GHCND:USW00013960                           DALLAS FAA AIRPORT TX US      134.1    32.8519   -96.8555 20140701 85       94       76                       
-1
Caroline 4 Май 2021 в 01:57

1 ответ

Лучший ответ

Хорошо, я исправил ваше среднее вычисление:

def MonthMean(Tave,dates):
    # Compute a new column containing the average for the month.

    # Calculate monthly mean by sum(Tave) in corresponding month and dividing by total days for that month
    sumx = 0
    cntx = 0
    thismo = -1
    column = []
    for tave, date in zip(Tave, dates):
        if date.month != thismo:
            if thismo > 0:
                column.extend( [sumx/cntx] * cntx )
            sumx = 0
            cntx = 0
            thismo = date.month
        sumx += tave
        cntx += 1

    column.extend( [sumx/cntx] * cntx )
    return column

Затем я просто добавил это как четвертый сюжет:

    plot1 = ax.plot(dates, Tmax,'red',label='Max Temp.')
    plot2 = ax.plot(dates, Tmin,'blue',label='Min Temp.')    
    plot3 = ax.plot(dates, Tave,'black',label='Ave Temp.')   
    plot4 = ax.plot(dates, MonthMean(Tave,dates), 'green')

И это дает следующее: введите здесь описание изображения

1
Tim Roberts 3 Май 2021 в 23:40