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

(prog:13885): Gdk-CRITICAL **: 01:02:22.225: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
./prog:53: 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
./prog:40: 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