def plotForcingSubplots(tsdata, filename=None, ci=95, show_figure=False, save_fig_kwargs=None):
sns.set_context('paper')
expList = tsdata['expName'].unique()
nrows = 1
ncols = len(expList)
width = 2 * ncols
height = 2
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, sharey=True, figsize=(width, height))
def dataForExp(expName):
df = tsdata.query("expName == '%s'" % expName).copy()
df.drop(['expName'], axis=1, inplace=True)
df = pd.melt(df, id_vars=['runId'], var_name='year')
return df
for ax, expName in zip(axes, expList):
df = dataForExp(expName)
pos = expName.find('-')
title = expName[:pos] if pos >= 0 else expName
ax.set_title(title.capitalize())
tsm.tsplot(df, time='year', unit='runId', value='value', ci=ci, ax=ax)
ylabel = 'W m$^{-2}$' if ax == axes[0] else ''
ax.set_ylabel(ylabel)
ax.set_xlabel('') # no need to say "year"
ax.axhline(0, color='navy', linewidth=0.5, linestyle='-')
plt.setp(ax.get_xticklabels(), rotation=270)
plt.tight_layout()
# Save the file
if filename:
if isinstance(save_fig_kwargs, dict):
fig.savefig(filename, **save_fig_kwargs)
else:
fig.savefig(filename)
# Display the figure
if show_figure:
plt.show()
return fig
评论列表
文章目录