chat1
from 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 a grid plot
grid = gridplot([plots], ncols=2)
show(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)