Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improv: Add more relevant snippets to the snippets panel (2/2) #3743

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59ef9e8
new: Add `bokeh-0.py` - `line-plot`
Haleshot Feb 10, 2025
23cafed
new: Add `bokeh-1.py` - `scatter-plot`
Haleshot Feb 10, 2025
dddda24
new: Add `bokeh-2.py` - `layout`
Haleshot Feb 10, 2025
a71f75e
new: Add `bokeh-3.py` - `RT-DS`
Haleshot Feb 10, 2025
7cba5e2
new: Add `bokeh-4.py` - `dashboard`
Haleshot Feb 10, 2025
8cd45f8
new: Add `bokeh-5.py` - `stats-viz`
Haleshot Feb 10, 2025
6be1dea
new: Add `bokeh-6.py` - `TS`
Haleshot Feb 10, 2025
5de0e3f
new: Add `bokeh-7.py` - `categorical data`
Haleshot Feb 10, 2025
785e19c
new: Add `bokeh-8.py` - `heatmap`
Haleshot Feb 10, 2025
08bb7d3
new: Add `bokeh-9.py` - `networkx x bokeh`
Haleshot Feb 10, 2025
38afa56
new: Add `holoviews-0.py` - `hist + scatter`
Haleshot Feb 10, 2025
0ff35be
new: Add `holoviews-1.py` - `TS analysis`
Haleshot Feb 10, 2025
cfbf036
new: Add `holoviews-2.py` - `overlapping analysis`
Haleshot Feb 10, 2025
244dd8a
new: Add `holoviews-3.py` - `geodata`
Haleshot Feb 10, 2025
be5d007
new: Add `holoviews-4.py` - `linked`
Haleshot Feb 10, 2025
490d29a
new: Add `holoviews-5.py` - `TS`
Haleshot Feb 10, 2025
a4e495e
new: Add `holoviews-6.py` - `stat`
Haleshot Feb 10, 2025
2088992
new: Add `holoviews-7.py` - `adv data analysis`
Haleshot Feb 10, 2025
9dbcecb
new: Add `holoviews-8.py` - `mixed`
Haleshot Feb 10, 2025
20b83e5
new: Add `holoviews-9.py` - `stats layout`
Haleshot Feb 10, 2025
f817858
new: Add `holoviews-10.py` - `error`
Haleshot Feb 10, 2025
33a6ed8
new: Add `holoviews-11.py` - `curve ranges`
Haleshot Feb 10, 2025
5706a70
new: Add `plotly-0.py` - `line plot`
Haleshot Feb 10, 2025
be80af1
new: Add `plotly-1.py` - `scatter plot`
Haleshot Feb 10, 2025
43ff079
new: Add `plotly-2.py` - `TS`
Haleshot Feb 10, 2025
050f367
new: Add `plotly-3.py` - `heatmap`
Haleshot Feb 10, 2025
c95ba42
new: Add `plotly-4.py` - `dashboard`
Haleshot Feb 10, 2025
58b0a59
new: Add `plotly-5.py` - `finance`
Haleshot Feb 10, 2025
0f38902
new: Add `plotly-6.py` - `stats distr`
Haleshot Feb 10, 2025
6ffee00
new: Add `plotly-7.py` - `3D scatter`
Haleshot Feb 10, 2025
217ecb1
new: Add `plotly-8.py` - `geo map`
Haleshot Feb 10, 2025
6a3ba49
new: Add `plotly-9.py` - `analyze plot`
Haleshot Feb 10, 2025
776f133
new: Add `plotly-10.py` - `bubble chart`
Haleshot Feb 10, 2025
b1c46da
new: Add `plotly-11.py` - `dendrograms`
Haleshot Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions marimo/_snippets/data/bokeh-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2024 Marimo. All rights reserved.

import marimo

__generated_with = "0.11.0"
app = marimo.App()


@app.cell
def _(mo):
mo.md(
r"""
# Bokeh: Interactive Line Plot

Create an interactive line plot with pan, zoom, and hover tools.
Common usage: `figure(tools='pan,box_zoom,reset,save')`.
Commonly used in: time series analysis, trend visualization.
"""
)
return


@app.cell
def _():
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
import numpy as np

# Generate sample data
x = np.linspace(0, 10, 100)
y = np.sin(x) + np.random.normal(0, 0.1, 100)

# Create data source
source = ColumnDataSource(data=dict(x=x, y=y))

# Create figure with tools
p = figure(
height=400,
width=700,
tools='pan,box_zoom,wheel_zoom,reset,save,hover',
title='Interactive Line Plot'
)

# Add line with hover tooltips
p.line('x', 'y', line_width=2, source=source)
p.hover.tooltips = [
('x', '@x{0.00}'),
('y', '@y{0.00}')
]

p
return ColumnDataSource, figure, np, p, source, x, y


@app.cell
def _():
import marimo as mo
return (mo,)


if __name__ == "__main__":
app.run()
87 changes: 87 additions & 0 deletions marimo/_snippets/data/bokeh-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2024 Marimo. All rights reserved.
import marimo

__generated_with = "0.11.0"
app = marimo.App()


@app.cell
def __(mo):
mo.md(
r"""
# Bokeh: Interactive Scatter Plot

Create a scatter plot with interactive tools and color mapping.
Common usage: `figure(tools='box_select,lasso_select,reset')`.
Commonly used in: data exploration, cluster analysis, outlier detection.
"""
)
return


@app.cell
def __():
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, ColorBar
from bokeh.transform import linear_cmap
import numpy as np

# Generate sample clustered data
np.random.seed(42)
N = 500
x = np.random.normal(size=N)
y = np.random.normal(size=N)
color_value = np.random.uniform(size=N) # Value for color mapping

# Create data source
source = ColumnDataSource(data=dict(
x=x,
y=y,
color=color_value,
))

# Create figure with selection tools
p = figure(
height=400,
width=700,
tools='box_select,lasso_select,wheel_zoom,pan,reset,save',
title='Interactive Scatter Plot'
)

# Add points with color mapping
mapper = linear_cmap('color', 'Viridis256', 0, 1)
scatter = p.scatter('x', 'y',
size=8,
source=source,
fill_color=mapper,
line_color='white',
alpha=0.6,
selection_color='red',
nonselection_alpha=0.1)

# Add colorbar
color_bar = ColorBar(color_mapper=mapper['transform'],
width=8,
location=(0,0))
p.add_layout(color_bar, 'right')

# Add hover tooltips
p.hover.tooltips = [
('x', '@x{0.00}'),
('y', '@y{0.00}'),
('value', '@color{0.00}')
]

p
return (ColorBar, ColumnDataSource, color_bar, color_value, figure, linear_cmap,
mapper, np, p, scatter, source, x, y)


@app.cell
def __():
import marimo as mo
return mo,


if __name__ == "__main__":
app.run()
111 changes: 111 additions & 0 deletions marimo/_snippets/data/bokeh-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright 2024 Marimo. All rights reserved.
import marimo

__generated_with = "0.11.0"
app = marimo.App()


@app.cell
def __(mo):
mo.md(
r"""
# Bokeh: Linked Brushing and Selection

Create linked plots with synchronized selection.
Common usage: `layout([p1, p2])` with shared `ColumnDataSource`.
Commonly used in: exploratory data analysis, correlation analysis, outlier detection.
"""
)
return


@app.cell
def __():
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
from bokeh.layouts import row
import numpy as np

# Generate sample data
np.random.seed(42)
N = 1000
x = np.random.normal(0, 1, N)
y = x * 0.5 + np.random.normal(0, 0.5, N) # Positive correlation with x
z = x * -0.2 + np.random.normal(0, 0.2, N) # Negative correlation with x

# Create data source
source = ColumnDataSource(data=dict(x=x, y=y, z=z))

# Common figure properties
plot_config = dict(
height=400,
width=400,
tools='box_select,lasso_select,wheel_zoom,pan,reset,hover',
background_fill_color='#f5f5f5'
)

# Create first plot
p1 = figure(
title='Y vs X (Positive Correlation)',
**plot_config
)
p1.circle('x', 'y',
source=source,
size=8,
fill_color='navy',
fill_alpha=0.5,
line_color='white',
selection_color='red',
nonselection_alpha=0.1)

# Create second plot
p2 = figure(
title='Z vs X (Negative Correlation)',
**plot_config
)
p2.circle('x', 'z',
source=source,
size=8,
fill_color='navy',
fill_alpha=0.5,
line_color='white',
selection_color='red',
nonselection_alpha=0.1)

# Add hover tooltips
tooltip_config = [
('x', '@x{0.00}'),
('y', '@y{0.00}'),
('z', '@z{0.00}')
]
p1.hover.tooltips = tooltip_config
p2.hover.tooltips = tooltip_config

# Add grid styling
for p in [p1, p2]:
p.grid.grid_line_color = 'white'
p.grid.grid_line_width = 2
p.axis.axis_label_text_font_size = '12pt'
p.axis.axis_label_text_font_style = 'bold'

# Add axis labels
p1.xaxis.axis_label = 'X Value'
p1.yaxis.axis_label = 'Y Value'
p2.xaxis.axis_label = 'X Value'
p2.yaxis.axis_label = 'Z Value'

# Layout plots side by side
layout = row(p1, p2)

layout
return (ColumnDataSource, figure, layout, np, p1, p2, row, source, x, y, z)


@app.cell
def __():
import marimo as mo
return mo,


if __name__ == "__main__":
app.run()
105 changes: 105 additions & 0 deletions marimo/_snippets/data/bokeh-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright 2024 Marimo. All rights reserved.
import marimo

__generated_with = "0.11.0"
app = marimo.App()


@app.cell
def __(mo):
mo.md(
r"""
# Bokeh: Real-time Data Streaming

Create a real-time streaming visualization with rolling window.
Common usage: `ColumnDataSource` with periodic updates.
Commonly used in: system monitoring, IoT dashboards, live analytics.
"""
)
return


@app.cell
def __():
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, DatetimeTickFormatter
import numpy as np
from datetime import datetime, timedelta
import pandas as pd

# Initialize data with rolling window
window_size = 100
now = datetime.now()
times = [(now + timedelta(seconds=i)) for i in range(-window_size, 0)]

# Simulate metric data (e.g., system metrics)
values = np.random.normal(100, 10, window_size)
values_smooth = pd.Series(values).rolling(window=5).mean()

# Create data source
source = ColumnDataSource(data=dict(
time=times,
value=values,
value_smooth=values_smooth
))

# Create figure
p = figure(
height=400,
width=800,
title='Real-time Metric Monitoring',
x_axis_type='datetime',
tools='pan,box_zoom,wheel_zoom,reset,save'
)

# Add raw data line
p.line('time', 'value',
line_color='lightgray',
line_alpha=0.5,
line_width=1,
legend_label='Raw Data',
source=source)

# Add smoothed line
p.line('time', 'value_smooth',
line_color='navy',
line_width=2,
legend_label='Smoothed (5-point MA)',
source=source)

# Style the plot
p.grid.grid_line_alpha = 0.3
p.xaxis.formatter = DatetimeTickFormatter(
seconds="%Y-%m-%d %H:%M:%S",
minsec="%Y-%m-%d %H:%M:%S",
minutes="%Y-%m-%d %H:%M:%S",
hourmin="%Y-%m-%d %H:%M"
)
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'

# Add hover tool
p.hover.tooltips = [
('Time', '@time{%Y-%m-%d %H:%M:%S}'),
('Value', '@value{0.00}'),
('Smoothed', '@value_smooth{0.00}')
]
p.hover.formatters = {'@time': 'datetime'}

# Configure legend
p.legend.location = 'top_left'
p.legend.click_policy = 'hide'

p
return (ColumnDataSource, DatetimeTickFormatter, datetime, figure, now, np, p,
pd, source, timedelta, times, values, values_smooth, window_size)


@app.cell
def __():
import marimo as mo
return mo,


if __name__ == "__main__":
app.run()
Loading
Loading