Creating Bar Chart with Bokeh Charts Module

  • Share this:

Code introduction


The function uses the Bar class from the Bokeh library to create a bar chart and displays it. The data is passed as an argument, which includes the data and labels for the bar chart.


Technology Stack : The package and technology stack used by the code [Bokeh library, Bar class, bar chart, data visualization]

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
def random_bar_chart(data):
    from bokeh.plotting import figure, show
    from bokeh.charts import Bar

    # Create a bar chart using the Bar class from bokeh.charts
    b = Bar(data, labels=data.keys(), title="Random Bar Chart")
    
    # Create a new figure and add the bar chart to it
    p = figure(title="Bar Chart from Bokeh Charts Module", tools="pan,wheel_zoom,box_zoom,reset")
    p.add_layout(b)

    # Display the plot
    show(p)