【发布时间】:2014-02-02 21:34:21
【问题描述】:
所以我有这段代码可以很好地生成子图,并以网格形式布置。数据在 Pandas DataFrames 中。
我不知道如何将第二个数据系列添加到子图中?
所以现在我绘制fullyrs.Units 并且我想添加merged2.fcast.plot(style='r') 我似乎缺少获取子图图形的参考?我尝试过的一些事情最终会出现在“循环”之外。
#area_tabs=list(map(str, range(1, 28)))
area_tabs=['1','2','3']
nrows = int(math.ceil(len(area_tabs) / 2.))
figlen=nrows*7 #adjust the figure size height to be sized to the number of rows
plt.rcParams['figure.figsize'] = 25,figlen
fig, axs = plt.subplots(nrows, 2, sharey=False)
for ax, area_tabs in zip(axs.flat, area_tabs):
fullyrs,lastq,fcast_yr,projections,yrahead,aname,actdf,merged2,mergederrs,montdist,ols_test, mergedfcst=do_projections(actdf,aname)
# ax=merged2.fcast.plot(style='r') <<<< I want to get this to plot in the same sub-plot as below
fullyrs.Units.plot(ax=ax, title='Area: {0} Forecast for 2014 {1} vs. Actual 2013 of {2} '.format(unicode(aname),unicode(merged2['fcast'][-1:].values), lastyrtot))
【问题讨论】:
-
您已经使用
plt.subplots创建了ax,所以您是否只需将ax=ax传递给merged2.fcast.plot而不是设置ax=...? -
@Rauparaha,没错!谢谢!如果你回答我可以标记它
-
已完成,很高兴能够提供帮助!
标签: python matplotlib pandas