Skip to content

Commit c2f45a1

Browse files
claude[bot]github-actions[bot]MarkusNeusinger
authored
feat(bokeh): implement scatter-color-groups (#351)
## Summary Implements `scatter-color-groups` for **bokeh** library. **Parent Issue:** #208 **Sub-Issue:** #261 **Base Branch:** `plot/scatter-color-groups` **Attempt:** 1/3 ## Implementation - `plots/bokeh/scatter/scatter-color-groups/default.py` ## Features - Uses iris dataset as example data - Color-coded by species (3 groups) - Uses style guide color palette - 4800x2700px output size - Proper legend with capitalized species names - Styled font sizes for title, axes, and legend --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent e51b2ff commit c2f45a1

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

  • plots/bokeh/scatter/scatter-color-groups
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
scatter-color-groups: Scatter Plot with Color Groups
3+
Library: bokeh
4+
"""
5+
6+
import numpy as np
7+
import pandas as pd
8+
from bokeh.io import export_png
9+
from bokeh.models import ColumnDataSource
10+
from bokeh.plotting import figure
11+
12+
13+
# Data - Iris-like dataset
14+
np.random.seed(42)
15+
n_per_group = 50
16+
17+
data = pd.DataFrame({
18+
"sepal_length": np.concatenate([
19+
np.random.normal(5.0, 0.35, n_per_group),
20+
np.random.normal(5.9, 0.50, n_per_group),
21+
np.random.normal(6.6, 0.60, n_per_group),
22+
]),
23+
"sepal_width": np.concatenate([
24+
np.random.normal(3.4, 0.38, n_per_group),
25+
np.random.normal(2.8, 0.30, n_per_group),
26+
np.random.normal(3.0, 0.30, n_per_group),
27+
]),
28+
"species": ["setosa"] * n_per_group + ["versicolor"] * n_per_group + ["virginica"] * n_per_group,
29+
})
30+
31+
# Color palette (from style guide)
32+
colors = ["#306998", "#FFD43B", "#DC2626", "#059669", "#8B5CF6", "#F97316"]
33+
species_list = data["species"].unique().tolist()
34+
color_map = {species: colors[i] for i, species in enumerate(species_list)}
35+
data["color"] = data["species"].map(color_map)
36+
37+
# Create figure
38+
p = figure(
39+
width=4800,
40+
height=2700,
41+
title="Scatter Plot with Color Groups",
42+
x_axis_label="Sepal Length (cm)",
43+
y_axis_label="Sepal Width (cm)",
44+
)
45+
46+
# Plot each group separately for legend
47+
for species in species_list:
48+
species_data = data[data["species"] == species]
49+
source = ColumnDataSource(data={"x": species_data["sepal_length"], "y": species_data["sepal_width"]})
50+
p.scatter(
51+
x="x", y="y", source=source, size=12, alpha=0.7, color=color_map[species], legend_label=species.capitalize()
52+
)
53+
54+
# Styling
55+
p.title.text_font_size = "20pt"
56+
p.xaxis.axis_label_text_font_size = "20pt"
57+
p.yaxis.axis_label_text_font_size = "20pt"
58+
p.xaxis.major_label_text_font_size = "16pt"
59+
p.yaxis.major_label_text_font_size = "16pt"
60+
p.legend.label_text_font_size = "16pt"
61+
p.legend.location = "top_right"
62+
p.grid.grid_line_alpha = 0.3
63+
64+
# Save
65+
export_png(p, filename="plot.png")

0 commit comments

Comments
 (0)