我试图垂直显示两个图。我得到一个错误信息,在 show(column(west_fig, east_fig))
请你帮我理解一下这个错误信息。
版本:BokehJS 1.4.0 BokehJS 1.4.0成功加载。
注:我在Jupyter笔记本上运行这段代码。
## Detailed error message:
RuntimeError: 模型必须只属于一个文档,DaysTicker(id='2330',...)已经在一个文档中。
# Bokeh libraries
from bokeh.io import output_file, output_notebook
from bokeh.plotting import figure, show
from bokeh.layouts import column
# output to notebook
output_notebook()
# Plot the two visualizations in a vertical configuration
show(column(west_fig, east_fig))
####### west_fig #######
# Bokeh libraries
from bokeh.plotting import figure, show
from bokeh.io import output_file, output_notebook
from bokeh.models import ColumnDataSource, CDSView, GroupFilter
# Output to notebook
output_notebook()
# Convert `stDate` column to datetime column
west_top_2['stDate'] = pd.to_datetime(west_top_2['stDate'], format = '%Y-%m-%d')
# Create a ColumnDataSource
west_cds = ColumnDataSource(west_top_2)
# Create views for each team
rockets_view = CDSView(source = west_cds,
filters = [GroupFilter(column_name = 'teamAbbr', group = 'HOU')]
)
warriors_view = CDSView(source = west_cds,
filters = [GroupFilter(column_name = 'teamAbbr', group = 'GS')]
)
# Create and configure the figure
west_fig = figure(x_axis_type = 'datetime',
plot_height = 500,
plot_width = 600,
title = 'Western Conference Top 2 Teams Wins Race, 2017-18',
x_axis_label = 'Date',
y_axis_label = 'Wins',
toolbar_location = None
)
# Render the race as step lines
west_fig.step('stDate', 'gameWon', source = west_cds, view = rockets_view, color = '#CE1141', legend = 'Rockets')
west_fig.step('stDate', 'gameWon', source = west_cds, view = warriors_view, color = '#006BB6', legend = 'Warriors')
# Move the legend to the upper top-left corner
west_fig.legend.location = "top_left"
# Show the plot
show(west_fig)
####### east_fig #########
import pandas as pd
# Bokeh libraries
from bokeh.plotting import figure, show
from bokeh.io import output_file, output_notebook
from bokeh.models import ColumnDataSource, CDSView, GroupFilter
# Output to notebook
output_notebook()
# Convert stDate to datetime column
standings['stDate'] = pd.to_datetime(standings['stDate'], format = '%Y-%m-%d')
# Create a ColumnDataSource
standings_cds = ColumnDataSource(standings)
# Create views for each team
celtics_view = CDSView(source=standings_cds,
filters = [GroupFilter(column_name = 'teamAbbr', group = 'BOS')]
)
raptors_view = CDSView(source=standings_cds,
filters = [GroupFilter(column_name = 'teamAbbr', group = 'TOR')]
)
# Configure Figure object
east_fig = figure(x_axis_type = 'datetime',
plot_height = 500,
plot_width = 600,
title = 'Eastern Conference Top 2 Teams Wins Race, 2017-18',
x_axis_label = 'Date',
y_axis_label = 'Wins',
toolbar_location = None
)
# Render the race as step lines
east_fig.step('stDate', 'gameWon', color = '#007A33', legend = 'Celtics',
source = standings_cds, view = celtics_view)
east_fig.step('stDate', 'gameWon', color = '#CE1141', legend = 'Raptors',
source = standings_cds, view = raptors_view)
# Move the legend to the upper left hand corner
east_fig.legend.location = "top_left"
# Show the plot
show(east_fig)
在你的代码末尾只做一个show语句。这意味着删除 show(column(west_fig, east_fig)), show(west_fig), show(east_fig)
行,并在代码末尾添加 show(column(west_fig, east_fig))