Skip to content

Use vbar_stack when adding 2 vbars to same plot #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions notebooks/06_data_sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -295,34 +295,33 @@
"source": [
"from bokeh.plotting import figure, show\n",
"from bokeh.models import ColumnDataSource\n",
"from bokeh.palettes import HighContrast3\n",
"\n",
"# create ColumnDataSource based on DataFrame from the demo data set\n",
"source = ColumnDataSource(monthly_values_df)\n",
"\n",
"# set up the figure\n",
"p = figure(\n",
" height=300,\n",
" x_range=source.data[\"month_name\"], # use the sequence of strings from the \"month_name\" column as categories\n",
" width=750,\n",
")\n",
"\n",
"# create a line renderer with data from the \"freight\" column\n",
"p.vbar(\n",
" x=\"month_name\", # use the sequence of strings from the \"month_name\" column as categories\n",
" top=\"freight\", # use the sequence of values from the \"freight\" column as values\n",
" width=0.9,\n",
" source=source,\n",
")\n",
"# plot values from these columns\n",
"columns = [\"freight\", \"passengers\", \"mail\"]\n",
"\n",
"# create a second line renderer with data from a different column\n",
"p.vbar(\n",
" x=\"month_name\", # use the sequence of strings from the \"month_name\" column as categories\n",
" top=\"passengers\", # use the sequence of values from the \"passengers\" column as values\n",
" # top=\"mail\", # 🔁 use this line instead of the one above to use data from the \"mail\" column\n",
"# use vbar_stack that stacks multiple vbar renderers\n",
"p.vbar_stack(\n",
" columns,\n",
" x=\"month_name\",\n",
" width=0.9,\n",
" color=\"tomato\",\n",
" source=source,\n",
" color=HighContrast3, # use the HighContrast color palette\n",
" legend_label=columns,\n",
")\n",
"\n",
"# move legend to left, to avoid overlap with bars\n",
"p.legend.location = \"top_left\"\n",
"\n",
"show(p)"
]
},
Expand Down