我是Pandas和Matplotlib的新手,想绘制此DataFrame
season won team matches pct_won
0 2008/2009 28.0 Manchester United 38 73.684211
1 2009/2010 27.0 Manchester United 38 71.052632
2 2010/2011 23.0 Manchester United 38 60.526316
3 2011/2012 28.0 Manchester United 38 73.684211
4 2012/2013 28.0 Manchester United 38 73.684211
5 2013/2014 19.0 Manchester United 38 50.000000
6 2014/2015 20.0 Manchester United 38 52.631579
7 2015/2016 19.0 Manchester United 38 50.000000
Run Code Online (Sandbox Code Playgroud)
使用以下代码行:
ax = aggregated_frame.plot(x='season', y='pct_won', figsize=(8,8), marker='o', rot=90, title='Performance by season of Team: {}'.format(aggregated_frame.iloc[0]['team']))
ax.set_xticklabels(aggregated_frame.season)
ax.set_xlabel('')
ax.yaxis.grid()
ax.yaxis.set_major_formatter(mtick.PercentFormatter())
ax.legend(['Percentage of Matches Won'], fontsize=14)
for item in ([ax.title, ax.xaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(14);
Run Code Online (Sandbox Code Playgroud)
但是my的第一个值xticklabels在结果图中被删除:

我尝试了几个选项,甚至只是set ax.set_xticklabels([1,2,3,4,5,6,7,8]),但每次都会删除第一个值。
怎么了 任何帮助都超过了欢迎。
另外:为什么season首先将not 的值用作标签?如果我省略set_xticklabels,x轴上根本不会打印任何标签。
您也不要在未设置刻度位置的情况下设置标签。即,如果您使用的ax.set_xticklabels话,也总是需要使用ax.set_ticks(否则,可能会有例外,在这种情况下,您需要确切地知道自己在做什么)。
这里:
ax.set_xticks(range(len(df)))
ax.set_xticklabels(df.season)
Run Code Online (Sandbox Code Playgroud)
产生
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |