python - Matplotlib.pyplot scatter:将 ylim min 设置为零不起作用
问题描述
我使用下面的代码提取了一些表数据:
import pandas as pd
import matplotlib.pyplot as plt
stat_dict={'Disposals' : 0,
'Kicks' : 1,
'Marks' : 2,
'Handballs' : 3,
'Goals' : 4,
'Behinds' : 5,
'Hitouts' : 6,
'Tackles' : 7,
'Rebounds' : 8,
'Inside50s' : 9,
'Clearances': 9,
'Clangers' : 10,
'FreesFor' : 11,
'FreesAgainst' : 12,
'ContestedPosessions' : 13,
'UncontestedPosesseions' : 14,
'ContestedMarks' : 15,
'MarksInside50' : 16,
'OnePercenters' : 17,
'Bounces' : 18,
'GoalAssists' : 19,
'Timeplayed' : 20}
team_lower_case='fremantle'
player="Fyfe, Nat"
stat_required='Disposals'
rounds=7
tables = pd.read_html("https://afltables.com/afl/stats/teams/"
+str(team_lower_case)+"/2018_gbg.html")
for df in tables:
df.drop(df.columns[rounds+1:], axis=1, inplace=True) # remove
unwanted columns
df.columns = df.columns.droplevel(0) # remove extra index level
stat_table=tables[stat_dict[stat_required]]
player_stat=stat_table[stat_table["Player"]==player]
player_stat=player_stat.iloc[:,1:8]
哪个输出:
R1 R2 R3 R4 R5 R6 R7
8 22.0 29.0 38.0 25.0 43.0 27.0 33.0
然后我绘制这些数据:
plt.scatter(range(1,rounds+1),player_stat)
plt.show()
<a href="https://i.stack.imgur.com/yB7LR.png" rel="nofollow noreferrer"> 我想将 y 轴限制设置为零:
plt.ylim(0,50)
我也尝试过以下方法:
plt.ylim(ymin=0)
解决方案
推荐阅读
- hive - Hive 使用 PM/AM 转换字符串日期
- ruby-on-rails - 使用安全导航算子后增加时间
- node.js - 通过 REST 在 Github Enterprise 上访问组织中的私有存储库
- javascript - 在 consol Javascript 中显示类的属性
- c# - 在 C# 中使用非原始类型重新创建 C++ 联合类型时出现对齐错误
- python - 求解一组非线性方程,产生具有最小方差的输出
- regex - 在字符类中包含不间断的空格
- php - MySql While 循环查询时间过长
- c++ - 如何在sqlite3 c ++中绑定日期时间函数
- javascript - 为什么这个`do`-`while`循环在结束后重复最后一个值?