3

This is how the plot should look like(don't mind the label etc)enter image description hereGetting 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.

Eyal
  • 39
  • 3
  • 1
    Welcome to Stack Overflow! As we can't see your csv or data, please read up on posting a minimal, reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – Ted Aug 22 '19 at 13:30
  • can you share the contents of `max_record15 ` and a sample of `maxlst15`? – Yuca Aug 22 '19 at 13:38
  • This is maxlst: Date 01-01 156 01-02 139 01-03 133 01-04 106 01-05 128 01-06 189 01-07 217 01-08 194 01-09 178 01-10 100 01-11 156 – Eyal Aug 22 '19 at 13:53
  • That's max_record15: [ 39 106 126 127 130 137 207 209 230 249 250 258 259 260 270 271 292 305 306 307 308 309 321 340 341 342 343 344 345 346 347 348 349 356 357 358 359] – Eyal Aug 22 '19 at 13:54
  • @Eyal Try posting a sample of your `df`, such as `df.head()`, by editing your question and formatting it correctly. This will give us a better idea of what way your data looks like. – Ted Aug 22 '19 at 14:16
  • @Tom thanks, I uploaded a df.head() shot – Eyal Aug 22 '19 at 14:52
  • Screenshots aren't that helpful, so please copy the data here. [Provide a copy of the data](https://stackoverflow.com/questions/52413246/how-do-i-provide-a-reproducible-copy-of-my-existing-dataframe) – Trenton McKinney Aug 22 '19 at 15:29
  • Data copied, Thanks – Eyal Aug 22 '19 at 15:58
  • You are trying to plot dates in the same axes as some other numbers. How do you imagine this to work or look like? (In the sense of should the 1 of April appear left or right of the number 42?) – ImportanceOfBeingErnest Aug 22 '19 at 21:07
  • @ImportanceOfBeingErnest I added a pic of how the plot should look like eventually(don't mind the label etc) – Eyal Aug 23 '19 at 09:48

0 Answers0