Python Forum
Getting barplots from the dropdown menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting barplots from the dropdown menu
#1
I have several bar plots in same figure as below:

import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_notebook
from bokeh.transform import dodge
output_notebook()

df = pd.DataFrame({
    'Apple':[10,20,25],
    'IBM':[20,18,8],
    'Lenovo':[16,28,22],
    'Dell':[4,15,23],
    'Year':['2000', '2005', '2010']
})

source = ColumnDataSource(df)

p = figure(x_range=df['Year'], title="Bar plot",height=350)

p.vbar(x=dodge('Year', -0.3, range=p.x_range), top='Apple', source=source,
       width=0.19,  legend_label="Apple")
p.vbar(x=dodge('Year',  -0.1,  range=p.x_range), top='IBM', source=source,
       width=0.19,  legend_label="IBM")
p.vbar(x=dodge('Year',  0.1, range=p.x_range), top='Lenovo', source=source,
       width=0.19,  legend_label="Lenovo")
p.vbar(x=dodge('Year',  0.3, range=p.x_range), top='Dell', source=source,
       width=0.19,  legend_label="Dell")

p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.legend.orientation = "horizontal"

show(p)
I can instead use dropdown menu for the Year as below:

menu_widget = list(df['Year'])

#Create the Dropdown

menu_dropdown = Dropdown(label="Select Years", menu=menu_widget)


show(widgetbox(menu_dropdown))
How do I handle events for displaying indiviudal plots for each year .
https://docs.bokeh.org/en/2.4.2/docs/user_guide/interaction/widgets.html
Larz60+ write Sep-14-2022, 11:01 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Populate Dropdown list from Database TommyAutomagically 4 4,555 Nov-02-2021, 05:23 PM
Last Post: ndc85430
  open the html page from the django dropdown menu? shams 2 3,339 Jul-17-2021, 08:10 AM
Last Post: shams

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020