Bokeh Bar Chart Creation with Data Lists

  • Share this:

Code introduction


This function creates a bar chart using the Bokeh library, taking two lists as data for the x and y axes, and saves the generated chart as an HTML file.


Technology Stack : Bokeh

Code Type : Bokeh chart generation

Code Difficulty : Intermediate


                
                    
def create_random_bar_chart(x, y):
    from bokeh.plotting import figure, show
    from bokeh.io import output_file
    from bokeh.models import ColumnDataSource

    output_file("random_bar_chart.html")

    data = ColumnDataSource(data=dict(x=x, y=y))

    p = figure(title="Random Bar Chart", x_axis_label='X Values', y_axis_label='Y Values')
    p.vbar(x='x', top='y', width=0.9, source=data)

    show(p)                
              
Tags: