Skip to content

Commit

Permalink
grate_full_period_all with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mlares committed Apr 6, 2020
1 parent 50fe8c1 commit a0d6748
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions arcovid19.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,77 @@ def grate_full_period_all(

return ax

def grate_full_period_all_commented(
self, ax=None, argentina=True,
exclude=None, **kwargs
):
"""
method: grate_full_period_all_commented()
This function plots the time series, similar to grate_full_period_all,
but including a second axis and comments about the start of quarantine
"""

kwargs.setdefault("confirmed", True)
kwargs.setdefault("active", False)
kwargs.setdefault("recovered", False)
kwargs.setdefault("deceased", False)

exclude = [] if exclude is None else exclude

if ax is None:
ax = plt.gca()
fig = plt.gcf()

height = len(PROVINCIAS) - len(exclude) - int(argentina)
height = 4 if height <= 0 else (height)

fig.set_size_inches(12, height)

if argentina:
self.grate_full_period(provincia=None, ax=ax, **kwargs)

exclude = [] if exclude is None else exclude
exclude = [self.cstats.get_provincia_name_code(e)[1] for e in exclude]

for code in sorted(CODE_TO_POVINCIA):
if code in exclude:
continue
self.grate_full_period(provincia=code, ax=ax, **kwargs)

labels = [d.date() for d in self.cstats.dates]
ispace = int(len(labels)/10)
ticks = np.arange(len(labels))[::ispace]
slabels = [l.strftime("%d.%b") for l in labels][::ispace]
lmin = labels[0].strftime("%d.%b")
lmax = labels[-1].strftime("%d.%b")
t = []
d0 = dt.datetime.strptime("3/11/20", '%m/%d/%y') #pandemia: 11 marzo
for dd in self.cstats.dates:
elapsed_days = (dd - d0).days
t.append(elapsed_days)
t = np.array(t)

ax.set_xticks(ticks=ticks)
ax.set_xticklabels(labels=slabels, rotation=0)
ax.set_title(
"COVID-19 Grow in Argentina by Province\n"
f"{lmin} - {lmax}")
ax.set_xlabel("Date")
ax.set_ylabel("Number of cases")

# add a second axis
ax2 = ax.twiny()
ax2.set_xlim(ax.get_xlim())
ax2.set_xlabel("days from first case")
q1 = dt.datetime.strptime("3/20/20", '%m/%d/%y') #cuarentena: 20 marzo
d_ini = (q1 - d0).days
d_fin = ax2.get_xlim()[1]
ax2.axvspan(d_ini, d_fin, alpha=0.1, color='yellow')

return ax

def grate_full_period(
self, provincia=None, confirmed=True,
active=True, recovered=True, deceased=True,
Expand Down

0 comments on commit a0d6748

Please sign in to comment.