app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import pandas as pd from bokeh.plotting import figure, output_file, save from bokeh.layouts import column import os # Load CSV data into DataFrame df = pd.read_csv("data.csv") # Output folder setup os.makedirs("output_bokeh_charts", exist_ok=True) # Set output HTML file output_file("output_bokeh_charts/bokeh_charts.html", title="Bokeh Charts") # 1. Bar Chart bar_fig = figure(x_range=df['name'], height=350, title="Bar Chart: User Ages", toolbar_location=None, tools="") bar_fig.vbar(x=df['name'], top=df['age'], width=0.5, color="skyblue") bar_fig.xgrid.grid_line_color = None bar_fig.y_range.start = 0 # 2. Line Chart line_fig = figure(x_range=df['name'], height=350, title="Line Chart: User Ages", toolbar_location=None, tools="") line_fig.line(x=df['name'], y=df['age'], line_width=2, color="green") line_fig.circle(x=df['name'], y=df['age'], size=10, color="green") # 3. Scatter Plot scatter_fig = figure(x_range=df['name'], height=350, title="Scatter Plot: User Ages", toolbar_location=None, tools="") scatter_fig.circle(x=df['name'], y=df['age'], size=12, color="orange") # Combine all plots into a vertical layout layout = column(bar_fig, line_fig, scatter_fig) # Save as interactive HTML save(layout) print("Bokeh charts saved as interactive HTML in 'output_bokeh_charts' folder.") |