我想在x轴上绘制季节,在Green的Y轴上绘制管制百分比。该图显示不正确,如下所示:
如何获取matplotlib绘制正确的y轴值?
import pandas as pd
from matplotlib import pyplot as plt
pga = pd.read_csv('/Users/dpericks/Desktop/PGA_Data_Historical.csv')
dj = pga[(pga['Player Name'] == 'Dustin Johnson')
& (pga['Variable'] == 'Greens in Regulation Percentage - (%)')]
plt.plot(dj['Season'], dj['Value'])
答案 0 :(得分:1)
import pandas as pd
from matplotlib import pyplot as plt
pga = pd.read_csv('PGA_Data_Historical.csv')
dj = pga[(pga['Player Name'] == 'Dustin Johnson')
& (pga['Variable'] == 'Greens in Regulation Percentage - (%)')]
dj_numberic_values_ = pd.to_numeric(dj['Value'])
plt.plot(dj['Season'], dj_numberic_values_)
plt.show()
调试您的代码时,我意识到我们从string type
获得了dj['Value']
个变量。我必须将这些值转换为适当的数值,以便matplotlib
可以使用它们。希望对您有帮助。