def plotTimeSeries(df, xlabel='', ylabel='', box=False, zeroLine=False, title="", ygrid=False,
yticks=False, ymin=None, ymax=None, legend=False, legendY=None, yearStep=5,
outFile=None, sideLabel=False, labelColor=None, yFormat=None, transparent=False,
openFile=False, closeFig=True):
setupPlot()
fig, ax = plt.subplots(1, 1, figsize=(8, 4))
yearCols = filter(str.isdigit, df.columns)
x = map(int, yearCols)
y = list(df[yearCols].iloc[0])
plt.plot(x, y)
# TBD: see if this is worth doing
# space out year labels to every 5 years
#locs, labels = plt.xticks()
#plt.xticks(locs[::yearStep], yearCols[::yearStep])
if box == False:
sns.despine(left=True)
if yticks:
plt.tick_params(axis='y', direction='out', length=5, width=.75,
colors='k', left='on', right='off')
if zeroLine:
ax.axhline(0, color='k', linewidth=0.75, linestyle='-')
if ygrid:
ax.yaxis.grid(color='lightgrey', linestyle='solid')
if ymin is not None or ymax is not None:
ax.set_autoscale_on(False)
ax.set_ylim(ymin, ymax)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
if legend:
legendY = -0.2 if legendY is None else legendY
ax.legend(loc='upper center', bbox_to_anchor=(0.5, legendY))
else:
ax.legend([], frameon=False)
if title:
ax.set_title(title, y=1.05)
_finalizeFigure(fig, ax, outFile=outFile, sideLabel=sideLabel, labelColor=labelColor,
yFormat=yFormat, transparent=transparent, openFile=openFile, closeFig=closeFig)
return (fig, ax)
评论列表
文章目录