繁体   English   中英

使用 MatPlotLib 绘制数据

[英]Plotting Data Using MatPlotLib

我正在开始我的第一个数据科学项目。 第一步是 plot 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')

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

您应该从 dataframe 中获取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')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM