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. ['2020-02-09', 803],
  29. ['2020-02-10', 904],
  30. ['2020-02-11', 1011],
  31. ['2020-02-12', 1112],
  32. ['2020-02-13', 1354]]
  33.  
  34. def new_corona(df):
  35. fig, ax = plt.subplots(nrows=1, ncols=1)
  36. df.dropna().plot(ax=ax, style='b.-')
  37. dfr = df.iloc[:,:]
  38. dfr.ix[TSFIRST] = (0.0, )
  39. dfr.ix[TSLAST] = (AMAX, )
  40. dfr.interpolate(method='quadratic').plot(ax=ax, style='r-')
  41. ax.set_xlim([TSFIRST, TSLAST])
  42. ax.set_ylim([0, AMAX])
  43. ax.legend(loc='best')
  44. plt.show()
  45.  
  46. idx = np.zeros(DAYS)
  47. ts = pd.Series(idx, index=pd.date_range(TSFIRST, periods=DAYS))
  48. val = np.full((DAYS, 1), np.nan)
  49. df = pd.DataFrame(val, index=pd.date_range(TSFIRST, periods=DAYS), columns=['val'])
  50. for d in dat:
  51. ymd, v = d[0], float(d[1])
  52. df.ix[ymd] = (v, )
  53.  
  54. new_corona(df)
  55.  
Success #stdin #stdout #stderr 1.06s 106660KB
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:30926): Gdk-CRITICAL **: 01:26:48.449: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

(prog:30926): Gdk-CRITICAL **: 01:26:48.469: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
./prog:52: 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:38: 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:39: 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