fork(1) download
  1. import pandas as pd
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4. from datetime import datetime, timedelta
  5.  
  6. FMT = '%Y-%m-%d'
  7. get_ts = lambda dt: datetime.strftime(dt, FMT)
  8. get_dt = lambda ts: datetime.strptime(ts, FMT)
  9.  
  10. DAYS = 366 + 63
  11. TSFIRST = '2019-12-01'
  12. AMAX = np.exp(DAYS / 31)
  13. TSLAST = get_ts(get_dt(TSFIRST) + timedelta(DAYS - 1))
  14.  
  15. dat = [
  16. ['2020-01-28', 106],
  17. ['2020-01-29', 132],
  18. ['2020-01-30', 170],
  19. ['2020-01-31', 213],
  20. ['2020-02-01', 259],
  21. ['2020-02-02', 304],
  22. ['2020-02-03', 362],
  23. ['2020-02-04', 426],
  24. ['2020-02-05', 491],
  25. ['2020-02-06', 563],
  26. ['2020-02-07', 634],
  27. ['2020-02-08', 717]]
  28.  
  29. def new_corona(df):
  30. fig, ax = plt.subplots(nrows=1, ncols=1)
  31. df.dropna().plot(ax=ax, style='b.-')
  32. dfr = df.iloc[:,:]
  33. dfr.ix[TSFIRST] = (0.0, )
  34. dfr.ix[TSLAST] = (AMAX, )
  35. dfr.interpolate(method='quadratic').plot(ax=ax, style='r-')
  36. ax.set_xlim([TSFIRST, TSLAST])
  37. ax.set_ylim([0, AMAX])
  38. ax.legend(loc='best')
  39. plt.show()
  40.  
  41. idx = np.zeros(DAYS)
  42. ts = pd.Series(idx, index=pd.date_range(TSFIRST, periods=DAYS))
  43. val = np.full((DAYS, 1), np.nan)
  44. df = pd.DataFrame(val, index=pd.date_range(TSFIRST, periods=DAYS), columns=['val'])
  45. for d in dat:
  46. ymd, v = d[0], float(d[1])
  47. df.ix[ymd] = (v, )
  48.  
  49. new_corona(df)
  50.  
Success #stdin #stdout #stderr 1.19s 105924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(prog:15819): Gdk-CRITICAL **: 04:00:26.256: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

(prog:15819): Gdk-CRITICAL **: 04:00:26.280: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
./prog:47: DeprecationWarning: 
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://p...content-available-to-author-only...a.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
./prog:33: DeprecationWarning: 
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://p...content-available-to-author-only...a.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
./prog:34: DeprecationWarning: 
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://p...content-available-to-author-only...a.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated