简体   繁体   English

使用 MatPlotLib 绘制数据

[英]Plotting Data Using MatPlotLib

I'm starting my first data science project.我正在开始我的第一个数据科学项目。 First step is to plot all shots from the 2018 NHL season.第一步是 plot 2018 NHL 赛季的所有镜头。 Can't seem to figure out how to make the x and y coordinates pull from xCord and yCord columns both int64 data types.似乎无法弄清楚如何从 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')

Didn't run this code, cause I don't have your data, but it should work.没有运行此代码,因为我没有您的数据,但它应该可以工作。

You should get the x and y from your dataframe, but both of them are set as a list, [xCord'] and [yCord] .您应该从 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