Skip to main content

chat1

fromPS1='\[\e[2m\]\d\[\e[0m\]|\[\e[2m\]\@\[\e[0m\]|\[\e[3m\]\u\[\e[0m\]@\h:\[\e[38;5;139m\]\W\[\e[0m\]\$ bokeh.plotting import figure, show, output_notebook
from bokeh.layouts import gridplot
import polars as pl'

# Enable Bokeh to display plots in the notebook
output_notebook()

def plot_dataframes_with_titles_bokeh(dataframes_with_titles):
    """
    Plots scatter plots for a list of (title, DataFrame) tuples using Bokeh.
    
    Args:
    dataframes_with_titles (List[Tuple[str, pl.DataFrame]]): List of tuples where each tuple contains a title and a polars DataFrame.
    """
    plots = []
    for title, df in dataframes_with_titles:
        p = figure(title=title, x_axis_label=df.columns[0], y_axis_label=df.columns[1])
        p.scatter(df[:, 0], df[:, 1])
        plots.append(p)
    
    # Create the grid layout
    grid = [plots[i:i+2] for i in range(0, len(plots), 2)]
    show(gridplot(grid))

# Example usage
df1 = pl.DataFrame({
    "x": [1, 2, 3, 4, 5],
    "y": [10, 20, 30, 40, 50]
})

df2 = pl.DataFrame({
    "x": [1, 2, 3, 4, 5],
    "y": [15, 25, 35, 45, 55]
})

df3 = pl.DataFrame({
    "x": [1, 2, 3, 4, 5],
    "y": [5, 15, 25, 35, 45]
})

dataframes_with_titles = [
    ("Scatter Plot 1", df1),
    ("Scatter Plot 2", df2),
    ("Scatter Plot 3", df3)
]

plot_dataframes_with_titles_bokeh(dataframes_with_titles)