Random Bar Chart Creation with Bokeh

  • Share this:

Code introduction


This function creates a bar chart using the Bokeh library. The data is passed as a parameter, with the x-axis representing the horizontal coordinates of the data points and the y-axis representing the values of the data points.


Technology Stack : Bokeh, ColumnDataSource

Code Type : Data visualization

Code Difficulty : Intermediate


                
                    
def random_bar_chart(data):
    from bokeh.plotting import figure, show
    from bokeh.models import ColumnDataSource
    
    # Create a ColumnDataSource from the data
    source = ColumnDataSource(data=dict(x=data['x'], y=data['y']))
    
    # Create a new plot with a title and axis labels
    p = figure(title="Random Bar Chart", x_axis_label='X', y_axis_label='Y', plot_width=800, plot_height=600)
    
    # Add a bar renderer to the plot
    p.vbar(x='x', top='y', width=0.9, source=source)
    
    # Show the results
    show(p)