Pandas 更改绘图的间距?
我正在用熊猫绘制一个时间序列图,我的数据如下Pandas 更改绘图的间距?,pandas,matplotlib,Pandas,Matplotlib,我正在用熊猫绘制一个时间序列图,我的数据如下 1986-87 334 1987-88 331 1988-89 352 1989-90 380 1990-91 386 1991-92 386 1992-93 390 1993-94 403 1994-95 406 playercount = pd.DataFrame(t.groupby('season').size()) playercount.plot() plt.show() 我的代码如下所示 1986-87 334 1
1986-87 334
1987-88 331
1988-89 352
1989-90 380
1990-91 386
1991-92 386
1992-93 390
1993-94 403
1994-95 406
playercount = pd.DataFrame(t.groupby('season').size())
playercount.plot()
plt.show()
我的代码如下所示
1986-87 334
1987-88 331
1988-89 352
1989-90 380
1990-91 386
1991-92 386
1992-93 390
1993-94 403
1994-95 406
playercount = pd.DataFrame(t.groupby('season').size())
playercount.plot()
plt.show()
我想要比这个更放大的版本。目前,我的一个像素包含10年,我想修改它,使其更细粒度,即5年或更少。我可以更改哪些参数来实现此目的?要调整网格间距,请尝试调整下面的参数
n
:
n = 5
playercount.plot(xticks=playercount.index[::n], grid=True)
这意味着您正在使用每个n个索引值作为x轴上的记号
如果您的索引不是时间戳而是字符串,那么这应该可以工作
playercount.plot(xticks=[i for i in range(len(playercount.index)) if not i % n], grid=True)
你想改变网格间距吗?@Alexander,是的。我希望它在某种程度上更细粒度、更放大。我得到以下错误值error:invalid literal for float():2014-15。我是否必须将2011-12年的数据转换为2011年。