+-

此代码在Pandas数据框中绘制特定的列,并提供多个倍数:
area_tabs=['12']
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):
actdf, aname = get_data(area_tabs)
lastq,fcast_yr,projections,yrahead,aname,actdf,merged2,mergederrs,montdist,ols_test,mergedfcst=do_projections(actdf)
mergedfcst.tail(12).plot(ax=ax, title='Area: {0} Forecast for 2014 {1} \
vs. 2013 actual of {2}'.format(unicode(aname),unicode(merged2['fcast'] [-1:].values),unicode(merged2['Units'][-2:-1].values)))
具有大致如下所示的数据框:以日期为索引
Units fcast
date
2014-01-01 384 302
2014-02-01 NaN 343
2014-03-01 NaN 396
2014-04-01 NaN 415
2014-05-01 NaN 483
2014-06-01 NaN 513
我得到的情节看起来像:
水平的背景网格(单位)显示良好,但我不知道如何获取垂直的每月网格.我怀疑它可能被视为未成年人?但是即使那样也看不到在pyplot / matplot中指定它的位置?
最佳答案
在您的for循环中添加ax.xaxis.grid(True,which = [‘major’|’minor’|’both’])应该可以解决问题.
这里的主要目的是尽可能避免使用plt状态机功能,而直接在axis对象上进行操作.
编辑:
不要从字面上理解上面的代码片段.管道分隔的值只是伪正则表达式中提供的选项.如果需要主要刻度,请使用:ax.xaxis.grid(True,which =’major’)
点击查看更多相关文章
转载注明原文:python-使x轴网格显示在matplotlib中 - 乐贴网