generate_presi_graphs.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import matplotlib.dates as mdates
  4. from matplotlib import rcParams
  5. FONT_COLOR = '#595959'
  6. SUSCEPTIBLE = '#6399f7'
  7. INFECTIOUS = '#f56262'
  8. REMOVED = '#83eb5e'
  9. # rki data
  10. rki_data_path = 'datasets/COVID-19-Todesfaelle_in_Deutschland/COVID-19-Todesfaelle_Deutschland.csv'
  11. rki_data = pd.read_csv(rki_data_path)
  12. rki_data['Berichtsdatum'] = pd.to_datetime(rki_data['Berichtsdatum'], errors='coerce')
  13. specific_dates = rki_data[rki_data['Berichtsdatum'].dt.is_quarter_start]['Berichtsdatum']
  14. rcParams['font.family'] = 'Comfortaa'
  15. rcParams['font.size'] = 12
  16. rcParams['text.color'] = FONT_COLOR
  17. rcParams['axes.labelcolor'] = FONT_COLOR
  18. rcParams['xtick.color'] = FONT_COLOR
  19. rcParams['ytick.color'] = FONT_COLOR
  20. slide3 = plt.figure(figsize=(12,6))
  21. ax = slide3.add_subplot(111, facecolor='#dddddd', axisbelow=True)
  22. ax.set_facecolor('xkcd:white')
  23. ax.plot(rki_data['Berichtsdatum'], rki_data['Faelle_gesamt'], label='infections', c=INFECTIOUS, lw=3)
  24. ax.plot(rki_data['Berichtsdatum'], rki_data['Todesfaelle_gesamt'], label='death cases', c=REMOVED, lw=3)
  25. plt.yscale('log')
  26. plt.ylabel('amount of poeple')
  27. plt.xlabel('time')
  28. plt.title('Accumulated cases (RKI Data)')
  29. ax.yaxis.set_tick_params(length=0)
  30. leg = plt.legend()
  31. ax.yaxis.set_tick_params(length=0, which='both')
  32. ax.xaxis.set_tick_params(length=0, which='both')
  33. ax.grid(which='major', c='black', lw=0.2, ls='-')
  34. for spine in ('top', 'right', 'bottom', 'left'):
  35. ax.spines[spine].set_visible(False)
  36. plt.gca().set_xticks(specific_dates)
  37. plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
  38. plt.gcf().autofmt_xdate(rotation=45, ha='center')
  39. slide3.savefig('visualizations/slide3.png', transparent=True)