Getting a: ValueError: ordinal must be >= 1
while adding another element to the plot such as fill between or scatterplot to the line plot already exists.
If I remove the line plot, it lets me run the scatterplot/fill between.
This is the output of df.head(20):
Date Element Data_Value
18049 2005-01-01 TMAX 56
35479 2005-01-01 TMIN -39
49823 2005-01-01 TMAX 150
17153 2005-01-01 TMAX 150
49827 2005-01-01 TMIN -39
31718 2005-01-01 TMIN -44
55424 2005-01-01 TMAX 150
35771 2005-01-01 TMAX 122
35785 2005-01-01 TMIN -39
31715 2005-01-01 TMAX 156
39569 2005-01-01 TMAX 144
39565 2005-01-01 TMIN -22
3058 2005-01-01 TMAX 128
19772 2005-01-01 TMAX 128
19769 2005-01-01 TMIN -33
55102 2005-01-01 TMAX 67
1906 2005-01-01 TMIN -17
55067 2005-01-01 TMIN -28
39468 2005-01-01 TMIN -28
39454 2005-01-01 TMAX 28
This is the code:
df =
pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv', parse_dates=['Date'])
df = df.set_index('Date').sort_index()
df15 = df[df.index.year == 2015]
df15 = df15.reset_index()
df = df[~(df.index.year == 2015)]
df = df[~((df.index.month == 2) & (df.index.day == 29))]
df = df.reset_index()
df = df.sort_values(by = ['Date', 'Data_Value'], ascending = [1, 0])
maxlst = df.groupby(df['Date'].dt.strftime('%m-%d'))['Data_Value'].max().sort_index()
minlst = df.groupby(df['Date'].dt.strftime('%m-%d'))['Data_Value'].min().sort_index()
maxlst15 = df15.groupby(df15['Date'].dt.strftime('%m-%d'))['Data_Value'].max().sort_index()
minlst15 = df15.groupby(df15['Date'].dt.strftime('%m-%d'))['Data_Value'].min().sort_index()
max_record15 = np.where(maxlst15.values > maxlst.values)[0]
min_record15 = np.where(minlst15.values < minlst.values)[0]
date_lst = []
for dt in list(maxlst.sort_index().index):
date_lst.append(datetime.strptime(dt, "%m-%d"))
plt.figure()
plt.plot(date_lst, maxlst, '-', date_lst, minlst, '-')
#when adding this row i get the error:
plt.scatter(max_record15, maxlst15.iloc[max_record15], s=10, color='red', label='High temp record broken (2015)')
plt.scatter(min_record15, maxlst15.iloc[min_record15], s=10, color='green', label='Low temp record broken (2015)')
#this line gives my the same error:
#plt.gca().fill_between(range(len(minlst)), minlst, maxlst, facecolor='blue', alpha=0.25)
plt.show()
This is the error:
ValueError: ordinal must be >= 1
with a bunch of trace calls.