Skip to content

Commit

Permalink
Improve plots
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 29, 2023
1 parent 572c9b6 commit 8da4f74
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
2 changes: 2 additions & 0 deletions isimip_qa/mixins/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class FigurePlotMixin:
def write(self, fig, path):
path.parent.mkdir(exist_ok=True, parents=True)

plt.rcParams.update({'mathtext.default': 'regular'})

logger.info(f'write {path}')
try:
fig.savefig(path)
Expand Down
4 changes: 2 additions & 2 deletions isimip_qa/plots/cdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def create(self):
ax = axs.item(sp.irow, sp.icol)

ymin = self.get_ymin(sp, subplots)
ymax = self.get_ymax(sp, subplots)
ymax = 1.0

if sp.primary:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color=sp.color,
linestyle=sp.linestyle, label=sp.label, zorder=10)
if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color='grey', zorder=0)

Expand Down
12 changes: 9 additions & 3 deletions isimip_qa/plots/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ def create(self):
if sp.primary:
ax.plot(sp.df.index, sp.df[sp.var], label=sp.label, zorder=10)
if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.plot(sp.df.index, sp.df[sp.var], color='grey', zorder=0)

xlabel = 'date'
if self.extraction_class.specifier == 'count':
ylabel = f'{sp.var} [count]'
else:
ylabel = f'{sp.var} [{sp.attrs.get("units")}]'

ax.set_title(sp.title)
ax.set_xlabel('date')
ax.set_ylabel(f'{sp.var} [{sp.attrs.get("units")}]')
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_ylim(ymin, ymax)
ax.tick_params(bottom=True, labelbottom=True, left=True, labelleft=True)

Expand Down
12 changes: 7 additions & 5 deletions isimip_qa/plots/dayofyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class DayOfYearPlot(FigurePlotMixin, GridPlotMixin, Plot):

def get_df(self, dataset):
extraction = self.extraction_class(dataset, self.region, self.period)
return extraction.read().groupby(lambda x: x.dayofyear).mean()
df = extraction.read()
return (df.groupby(lambda x: x.dayofyear).mean() - df.min()) / (df.max() - df.min())

def get_attrs(self, dataset):
return AttrsExtraction(dataset, self.region, self.period).read()
Expand All @@ -39,12 +40,13 @@ def create(self):
ymax = self.get_ymax(sp, subplots)

if sp.primary:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color=sp.color,
linestyle=sp.linestyle, label=sp.label, zorder=10)
ax.plot(sp.df.index, sp.df[sp.var], '.', color=sp.color,
linestyle='', label=sp.label, zorder=10)

if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color='grey', zorder=0)
ax.plot(sp.df.index, sp.df[sp.var], '.', color='grey', zorder=0)

ax.set_title(sp.title)
ax.set_xlabel('day of the year')
Expand Down
7 changes: 6 additions & 1 deletion isimip_qa/plots/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ def create(self):
ax.tick_params(bottom=True, labelbottom=True, left=True, labelleft=True)

if ax not in cbars:
if self.extraction_class.specifier == 'countmap':
label = f'{sp.var} [count]'
else:
label = f'{sp.var} [{sp.attrs.get("units")}]'

cbar = plt.colorbar(im, ax=ax)
cbar.set_label(f'{sp.var} [{sp.attrs.get("units")}]')
cbar.set_label(label)
cbar.set_ticks([vmin, vmax])
cbars.append(ax)

Expand Down
12 changes: 7 additions & 5 deletions isimip_qa/plots/monthofyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MonthOfYearPlot(FigurePlotMixin, GridPlotMixin, Plot):

def get_df(self, dataset):
extraction = self.extraction_class(dataset, self.region, self.period)
return extraction.read().groupby(lambda x: x.month).mean()
df = extraction.read()
return (df.groupby(lambda x: x.month).mean() - df.min()) / (df.max() - df.min())

def get_attrs(self, dataset):
return AttrsExtraction(dataset, self.region, self.period).read()
Expand All @@ -39,16 +40,17 @@ def create(self):
ymax = self.get_ymax(sp, subplots)

if sp.primary:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color=sp.color,
ax.plot(sp.df.index, sp.df[sp.var], 'o', color=sp.color,
linestyle=sp.linestyle, label=sp.label, zorder=10)
if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color='grey', zorder=0)
ax.plot(sp.df.index, sp.df[sp.var], 'o', color='grey', zorder=0)

ax.set_title(sp.title)
ax.set_xlabel('month of the year')
ax.set_ylabel(f'{sp.var} [{sp.attrs.get("units")}]')
ax.set_ylabel(fr'({sp.var} - ${sp.var}_{{min}})$ / (${sp.var}_{{max}}$ - ${sp.var}_{{min}}$)'
fr' [{sp.attrs.get("units")}]')
ax.set_ylim(ymin, ymax)
ax.tick_params(bottom=True, labelbottom=True, left=True, labelleft=True)

Expand Down
2 changes: 1 addition & 1 deletion isimip_qa/plots/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create(self):
ax.step(sp.df.index, sp.df[sp.var], where='mid', color=sp.color,
linestyle=sp.linestyle, label=sp.label, zorder=10)
if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color='grey', zorder=0)

Expand Down
9 changes: 6 additions & 3 deletions isimip_qa/plots/yearly.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ def create(self):
ax.step(sp.df.index, sp.df[sp.var], where='mid', color=sp.color,
linestyle=sp.linestyle, label=sp.label, zorder=10)
if sp.label:
ax.legend(loc='lower left').set_zorder(20)
ax.legend(loc='best').set_zorder(20)
else:
ax.step(sp.df.index, sp.df[sp.var], where='mid', color='grey', zorder=0)

xlabel = 'date'
ylabel = fr'${sp.var}_{{yearly}}$ [{sp.attrs.get("units")}]'

ax.set_title(sp.title)
ax.set_xlabel('date')
ax.set_ylabel(f'{sp.var} [{sp.attrs.get("units")}]')
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_ylim(ymin, ymax)
ax.tick_params(bottom=True, labelbottom=True, left=True, labelleft=True)

Expand Down

0 comments on commit 8da4f74

Please sign in to comment.