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

(prog:31375): Gdk-CRITICAL **: 04:56:56.357: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
./prog:48: 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
./prog:35: 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