【问题标题】:Plotting Data Using MatPlotLib [duplicate]使用 MatPlotLib 绘制数据
【发布时间】:2022-01-27 13:40:11
【问题描述】:

我正在开始我的第一个数据科学项目。第一步是绘制 2018 NHL 赛季的所有镜头。似乎无法弄清楚如何从 xCord 和 yCord 列中提取 x 和 y 坐标,这两种数据类型都是 int64 数据类型。

import pandas as pd
import numpy as py
import matplotlib.pyplot as plt

shots = pd.read_csv('NHL_Project/Data/shots_2007-2020.csv')

shot = shots[['homeTeamCode', 'awayTeamCode', 'season','isPlayoffGame','game_id','homeTeamWon', 'period', 'time','period','team','location','event','goal','xCord','yCord','shotType','playerPositionThatDidEvent','playerNumThatDidEvent','goalieIdForShot','goalieNameForShot','shooterPlayerId','shooterName','shooterLeftRight','shotWasOnGoal']].head()

fig = plt.figure(figsize=(100,100))
ax = plt.axes()
t = py.linspace(-100, 100, 100) # return 100 numbers between -100 and 100
x = ['xCord']
y = ['yCord']

ax.plot(x, y, color='red', marker='D')

【问题讨论】:

    标签: python python-3.x matplotlib


    【解决方案1】:

    没有运行此代码,因为我没有您的数据,但它应该可以工作。

    您应该从数据框中获取xy,但它们都设置为列表[xCord'][yCord]

    import pandas as pd
    import numpy as py
    import matplotlib.pyplot as plt
    
    shots = pd.read_csv('NHL_Project/Data/shots_2007-2020.csv')
    
    shot = shots[['homeTeamCode', 'awayTeamCode', 'season','isPlayoffGame','game_id','homeTeamWon', 'period', 'time','period','team','location','event','goal','xCord','yCord','shotType','playerPositionThatDidEvent','playerNumThatDidEvent','goalieIdForShot','goalieNameForShot','shooterPlayerId','shooterName','shooterLeftRight','shotWasOnGoal']].head()
    
    fig = plt.figure(figsize=(100,100))
    ax = plt.axes()
    t = py.linspace(-100, 100, 100) # return 100 numbers between -100 and 100
    
    ax.plot(x=shots.xCord, y=shots.yCord, color='red', marker='D')
    

    【讨论】:

    • 太棒了!也感谢您的快速响应。
    • 不用担心。如果对您有用,请接受答案。
    猜你喜欢
    • 2014-05-28
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多