此代码不起作用并返回错误:
AttributeError: 'Rectangle' object has no property 'normed'
我认为它应该工作,因为它是复制粘贴从:
https://github.com/dashee87/blogScripts/blob/master/Jupyter/2017-06-04-predicting-football-results-with-statistical-modelling.ipynb
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
epl_1617 = pd.read_csv("https://www.football-data.co.uk/mmz4281/1617/E0.csv")
epl_1617 = epl_1617[['HomeTeam','AwayTeam','FTHG','FTAG']]
epl_1617 = epl_1617.rename(columns={'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals'})
poisson_pred = np.column_stack([[poisson.pmf(i, epl_1617.mean()[j]) for i in range(8)] for j in range(2)])
plt.hist(epl_1617[['HomeGoals', 'AwayGoals']].values, range(9),
alpha=0.7, label=['Home', 'Away'],normed=True, color=["#FFA07A", "#20B2AA"])
我使用的是Python 3.7和matplotlib 3.5.1
1条答案
按热度按时间xpcnnkqh1#
你有没有试过
从plt.hist()的参数中得到的?
可能是matplotlib. pyplot的版本不匹配。我的版本是python3.10.10,matplotlib-3.7.0,也有类似的问题。删除“normed= True”后,我得到了
在你提供的示例代码中还有另一个问题,应该先导入poisson。