Cannot get Bokeh graph to show using Python
up vote
0
down vote
favorite
I'm pretty new to Python and this is my first time using Bokeh. I've followed a tutorial using NFL data to show graphs and I cannot get the graph to show on my machine. The script runs without error, but nothing shows. I'm sure I'm missing something very simple... but I just don't know what that is... Can someone please help me? Below is my code:
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, FactorRange, FixedTicker
from bokeh.io import output_notebook
from collections import Counter
from bokeh.transform import factor_cmap
from bokeh.palettes import Paired, Spectral
import itertools
pd.set_option('display.max_columns', 150)
output_notebook()
filename = '/Users/ksilva/Downloads/NFL Play by Play 2009-2017 (v4).csv'
df = pd.read_csv(filename,dtype={25: object, 51: object})
# print(df.shape)
# df['down'].isnull().sum()
pd.to_numeric(df['down'], errors='coerce').isnull().sum()
# print(df.loc[51])
# filter by team if desired
team = 'all'
if team == 'all':
team_df = df
else:
team_df = df.loc[df['posteam'] == team]
# drop rows will null in the 'down' column
team_df = team_df.loc[df['down'].notnull()]
all_play_types = Counter(team_df['PlayType'])
# print(team_df)
# print(all_play_types)
# list of downs I care about
downs = ['1','2','3','4']
# list of plays I care about
plays = ['Pass', 'Run', 'Punt', 'Field Goal']
# define x-axis categories to be used in the vbar plot
x = list(itertools.product(downs, plays))
# x = [('1', 'Pass'), ('1', 'Run'), ('1', 'Punt'), ..., ('4', 'Punt'), ('4', 'Field Goal')]
# create a list of Counters for each down--will include ALL PlayTypes for each down
plays_on_down = [Counter(team_df.loc[team_df['down'] == int(down)]['PlayType']) for down in downs]
# create a list of counts for each play in plays for each down in downs
counts = [plays_on_down[int(down)-1][play] for down, play in x]
# load the into the ColumnDataSource
source = ColumnDataSource(data=dict(x=x, counts=counts))
# get the figure ready
p = figure(x_range=FactorRange(*x), plot_height=350, plot_width=750, title='Play by Down',
toolbar_location=None, tools='')
# create the vbar
p.vbar(x='x', top='counts', width=0.9, source=source, line_color='white',
fill_color=factor_cmap('x', palette=Spectral[4], factors=plays, start=1, end=2))
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xaxis.axis_label = 'Down'
p.yaxis.axis_label = 'Number of Plays'
p.xgrid.grid_line_color = None
show(p)
For whatever reason, nothing happens when executed from the terminal.
Any help is greatly appreciated!
Thanks.
python-3.x terminal bokeh
add a comment |
up vote
0
down vote
favorite
I'm pretty new to Python and this is my first time using Bokeh. I've followed a tutorial using NFL data to show graphs and I cannot get the graph to show on my machine. The script runs without error, but nothing shows. I'm sure I'm missing something very simple... but I just don't know what that is... Can someone please help me? Below is my code:
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, FactorRange, FixedTicker
from bokeh.io import output_notebook
from collections import Counter
from bokeh.transform import factor_cmap
from bokeh.palettes import Paired, Spectral
import itertools
pd.set_option('display.max_columns', 150)
output_notebook()
filename = '/Users/ksilva/Downloads/NFL Play by Play 2009-2017 (v4).csv'
df = pd.read_csv(filename,dtype={25: object, 51: object})
# print(df.shape)
# df['down'].isnull().sum()
pd.to_numeric(df['down'], errors='coerce').isnull().sum()
# print(df.loc[51])
# filter by team if desired
team = 'all'
if team == 'all':
team_df = df
else:
team_df = df.loc[df['posteam'] == team]
# drop rows will null in the 'down' column
team_df = team_df.loc[df['down'].notnull()]
all_play_types = Counter(team_df['PlayType'])
# print(team_df)
# print(all_play_types)
# list of downs I care about
downs = ['1','2','3','4']
# list of plays I care about
plays = ['Pass', 'Run', 'Punt', 'Field Goal']
# define x-axis categories to be used in the vbar plot
x = list(itertools.product(downs, plays))
# x = [('1', 'Pass'), ('1', 'Run'), ('1', 'Punt'), ..., ('4', 'Punt'), ('4', 'Field Goal')]
# create a list of Counters for each down--will include ALL PlayTypes for each down
plays_on_down = [Counter(team_df.loc[team_df['down'] == int(down)]['PlayType']) for down in downs]
# create a list of counts for each play in plays for each down in downs
counts = [plays_on_down[int(down)-1][play] for down, play in x]
# load the into the ColumnDataSource
source = ColumnDataSource(data=dict(x=x, counts=counts))
# get the figure ready
p = figure(x_range=FactorRange(*x), plot_height=350, plot_width=750, title='Play by Down',
toolbar_location=None, tools='')
# create the vbar
p.vbar(x='x', top='counts', width=0.9, source=source, line_color='white',
fill_color=factor_cmap('x', palette=Spectral[4], factors=plays, start=1, end=2))
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xaxis.axis_label = 'Down'
p.yaxis.axis_label = 'Number of Plays'
p.xgrid.grid_line_color = None
show(p)
For whatever reason, nothing happens when executed from the terminal.
Any help is greatly appreciated!
Thanks.
python-3.x terminal bokeh
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm pretty new to Python and this is my first time using Bokeh. I've followed a tutorial using NFL data to show graphs and I cannot get the graph to show on my machine. The script runs without error, but nothing shows. I'm sure I'm missing something very simple... but I just don't know what that is... Can someone please help me? Below is my code:
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, FactorRange, FixedTicker
from bokeh.io import output_notebook
from collections import Counter
from bokeh.transform import factor_cmap
from bokeh.palettes import Paired, Spectral
import itertools
pd.set_option('display.max_columns', 150)
output_notebook()
filename = '/Users/ksilva/Downloads/NFL Play by Play 2009-2017 (v4).csv'
df = pd.read_csv(filename,dtype={25: object, 51: object})
# print(df.shape)
# df['down'].isnull().sum()
pd.to_numeric(df['down'], errors='coerce').isnull().sum()
# print(df.loc[51])
# filter by team if desired
team = 'all'
if team == 'all':
team_df = df
else:
team_df = df.loc[df['posteam'] == team]
# drop rows will null in the 'down' column
team_df = team_df.loc[df['down'].notnull()]
all_play_types = Counter(team_df['PlayType'])
# print(team_df)
# print(all_play_types)
# list of downs I care about
downs = ['1','2','3','4']
# list of plays I care about
plays = ['Pass', 'Run', 'Punt', 'Field Goal']
# define x-axis categories to be used in the vbar plot
x = list(itertools.product(downs, plays))
# x = [('1', 'Pass'), ('1', 'Run'), ('1', 'Punt'), ..., ('4', 'Punt'), ('4', 'Field Goal')]
# create a list of Counters for each down--will include ALL PlayTypes for each down
plays_on_down = [Counter(team_df.loc[team_df['down'] == int(down)]['PlayType']) for down in downs]
# create a list of counts for each play in plays for each down in downs
counts = [plays_on_down[int(down)-1][play] for down, play in x]
# load the into the ColumnDataSource
source = ColumnDataSource(data=dict(x=x, counts=counts))
# get the figure ready
p = figure(x_range=FactorRange(*x), plot_height=350, plot_width=750, title='Play by Down',
toolbar_location=None, tools='')
# create the vbar
p.vbar(x='x', top='counts', width=0.9, source=source, line_color='white',
fill_color=factor_cmap('x', palette=Spectral[4], factors=plays, start=1, end=2))
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xaxis.axis_label = 'Down'
p.yaxis.axis_label = 'Number of Plays'
p.xgrid.grid_line_color = None
show(p)
For whatever reason, nothing happens when executed from the terminal.
Any help is greatly appreciated!
Thanks.
python-3.x terminal bokeh
I'm pretty new to Python and this is my first time using Bokeh. I've followed a tutorial using NFL data to show graphs and I cannot get the graph to show on my machine. The script runs without error, but nothing shows. I'm sure I'm missing something very simple... but I just don't know what that is... Can someone please help me? Below is my code:
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, FactorRange, FixedTicker
from bokeh.io import output_notebook
from collections import Counter
from bokeh.transform import factor_cmap
from bokeh.palettes import Paired, Spectral
import itertools
pd.set_option('display.max_columns', 150)
output_notebook()
filename = '/Users/ksilva/Downloads/NFL Play by Play 2009-2017 (v4).csv'
df = pd.read_csv(filename,dtype={25: object, 51: object})
# print(df.shape)
# df['down'].isnull().sum()
pd.to_numeric(df['down'], errors='coerce').isnull().sum()
# print(df.loc[51])
# filter by team if desired
team = 'all'
if team == 'all':
team_df = df
else:
team_df = df.loc[df['posteam'] == team]
# drop rows will null in the 'down' column
team_df = team_df.loc[df['down'].notnull()]
all_play_types = Counter(team_df['PlayType'])
# print(team_df)
# print(all_play_types)
# list of downs I care about
downs = ['1','2','3','4']
# list of plays I care about
plays = ['Pass', 'Run', 'Punt', 'Field Goal']
# define x-axis categories to be used in the vbar plot
x = list(itertools.product(downs, plays))
# x = [('1', 'Pass'), ('1', 'Run'), ('1', 'Punt'), ..., ('4', 'Punt'), ('4', 'Field Goal')]
# create a list of Counters for each down--will include ALL PlayTypes for each down
plays_on_down = [Counter(team_df.loc[team_df['down'] == int(down)]['PlayType']) for down in downs]
# create a list of counts for each play in plays for each down in downs
counts = [plays_on_down[int(down)-1][play] for down, play in x]
# load the into the ColumnDataSource
source = ColumnDataSource(data=dict(x=x, counts=counts))
# get the figure ready
p = figure(x_range=FactorRange(*x), plot_height=350, plot_width=750, title='Play by Down',
toolbar_location=None, tools='')
# create the vbar
p.vbar(x='x', top='counts', width=0.9, source=source, line_color='white',
fill_color=factor_cmap('x', palette=Spectral[4], factors=plays, start=1, end=2))
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xaxis.axis_label = 'Down'
p.yaxis.axis_label = 'Number of Plays'
p.xgrid.grid_line_color = None
show(p)
For whatever reason, nothing happens when executed from the terminal.
Any help is greatly appreciated!
Thanks.
python-3.x terminal bokeh
python-3.x terminal bokeh
asked Nov 21 at 18:17
Kai
153
153
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17
add a comment |
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You are setting calling output_notebook
. This activates a mode that only diplays in a Jupyter notebook. If you want to execute plain python scripts to generate HTML file output, you should use output_file
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You are setting calling output_notebook
. This activates a mode that only diplays in a Jupyter notebook. If you want to execute plain python scripts to generate HTML file output, you should use output_file
.
add a comment |
up vote
0
down vote
accepted
You are setting calling output_notebook
. This activates a mode that only diplays in a Jupyter notebook. If you want to execute plain python scripts to generate HTML file output, you should use output_file
.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You are setting calling output_notebook
. This activates a mode that only diplays in a Jupyter notebook. If you want to execute plain python scripts to generate HTML file output, you should use output_file
.
You are setting calling output_notebook
. This activates a mode that only diplays in a Jupyter notebook. If you want to execute plain python scripts to generate HTML file output, you should use output_file
.
answered Nov 21 at 18:28
bigreddot
16.9k23264
16.9k23264
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418288%2fcannot-get-bokeh-graph-to-show-using-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Here is the tutorial that I'm following: j253.github.io/blog/fun-with-nfl-stats.html
– Kai
Nov 21 at 18:17