pandas - 绘制熊猫数据框时缺少 xticklabels 的第一个值
问题描述
我是 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
使用这些代码行:
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);
但是 my 的第一个值xticklabels
在结果图中被删除:
我尝试了几个选项,甚至只是 set ax.set_xticklabels([1,2,3,4,5,6,7,8])
,但每次都删除第一个值。
这里有什么问题?任何帮助都非常受欢迎。
另外:为什么season
首先不将值用作标签?如果我省略set_xticklabels
了 x 轴上根本没有打印任何标签。
解决方案
推荐阅读
- excel - 将多个工作簿中的值合并到一个工作簿
- python - 在 Selenium 中处理动态页面
- python - 使用 *args 和 seaborn 绘图时如何显示所有图例
- kubernetes - kubectl 日志返回“您的意思是运行 dotnet SDK 命令吗?请安装 dotnet SDK”
- qt - 是否可以在 Qt 资源文件中使用系统环境变量?
- javascript - 动态 import() 并渲染一个 React 组件模块
- r - 函数 somersD 返回 NaN
- java - 不和谐 JDA GatewayIntent.GUILD_MEMBERS 用法?
- python - 我将如何通过 python 访问网站的对象?
- r - 如何使 UpdateSelectInput 正常工作?