Skip to content

Commit e50192d

Browse files
feat(plotly): implement facet-grid (#6515)
## Implementation: `facet-grid` - python/plotly Implements the **python/plotly** version of `facet-grid`. **File:** `plots/facet-grid/implementations/python/plotly.py` **Parent Issue:** #2696 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25776278040)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 6f28863 commit e50192d

2 files changed

Lines changed: 195 additions & 158 deletions

File tree

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
facet-grid: Faceted Grid Plot
3-
Library: plotly 6.5.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-30
3+
Library: plotly 6.7.0 | Python 3.13.13
4+
Quality: 92/100 | Updated: 2026-05-13
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
911
import plotly.express as px
1012

1113

12-
# Data - Create realistic dataset for faceted visualization
14+
THEME = os.getenv("ANYPLOT_THEME", "light")
15+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
16+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
17+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
18+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
19+
GRID = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"
20+
BRAND = "#009E73"
21+
22+
# Data
1323
np.random.seed(42)
1424

15-
# Product performance data across regions and quarters
1625
regions = ["North", "South", "East", "West"]
1726
quarters = ["Q1", "Q2", "Q3", "Q4"]
1827

1928
data = []
2029
for region in regions:
2130
for quarter in quarters:
22-
# Generate 15 data points per region-quarter combination
2331
n = 15
24-
# Base values vary by region and quarter
2532
base_sales = {"North": 80, "South": 60, "East": 70, "West": 75}
2633
quarter_effect = {"Q1": 0, "Q2": 10, "Q3": 5, "Q4": 15}
2734

@@ -45,30 +52,31 @@
4552

4653
df = pd.DataFrame(data)
4754

48-
# Create faceted scatter plot
49-
# Using single color since Region is already encoded by facet rows
55+
# Plot
5056
fig = px.scatter(df, x="Marketing Spend ($K)", y="Sales ($K)", facet_row="Region", facet_col="Quarter")
5157

52-
# Update layout for large canvas
58+
# Style
5359
fig.update_layout(
54-
title=dict(text="facet-grid · plotly · pyplots.ai", font=dict(size=32), x=0.5, xanchor="center"),
55-
font=dict(size=16),
56-
template="plotly_white",
60+
title={"text": "facet-grid · plotly · anyplot.ai", "font": {"size": 28, "color": INK}, "x": 0.5, "xanchor": "center"},
61+
paper_bgcolor=PAGE_BG,
62+
plot_bgcolor=PAGE_BG,
63+
font={"color": INK},
5764
showlegend=False,
58-
margin=dict(l=80, r=80, t=100, b=80),
65+
margin={"l": 80, "r": 80, "t": 100, "b": 80},
5966
)
6067

61-
# Update axes for all facets
62-
fig.update_xaxes(title_font=dict(size=20), tickfont=dict(size=16), gridcolor="rgba(0,0,0,0.1)", gridwidth=1)
68+
fig.update_xaxes(
69+
title_font={"size": 22, "color": INK}, tickfont={"size": 18, "color": INK_SOFT}, gridcolor=GRID, linecolor=INK_SOFT
70+
)
6371

64-
fig.update_yaxes(title_font=dict(size=20), tickfont=dict(size=16), gridcolor="rgba(0,0,0,0.1)", gridwidth=1)
72+
fig.update_yaxes(
73+
title_font={"size": 22, "color": INK}, tickfont={"size": 18, "color": INK_SOFT}, gridcolor=GRID, linecolor=INK_SOFT
74+
)
6575

66-
# Update facet labels (annotations)
67-
fig.for_each_annotation(lambda a: a.update(font=dict(size=18)))
76+
fig.for_each_annotation(lambda a: a.update(font={"size": 18, "color": INK}))
6877

69-
# Update markers with consistent color for visibility
70-
fig.update_traces(marker=dict(size=12, opacity=0.8, color="#306998", line=dict(width=1, color="white")))
78+
fig.update_traces(marker={"size": 16, "opacity": 0.8, "color": BRAND, "line": {"width": 1, "color": PAGE_BG}})
7179

72-
# Save as PNG and HTML
73-
fig.write_image("plot.png", width=1600, height=900, scale=3)
74-
fig.write_html("plot.html", include_plotlyjs="cdn")
80+
# Save
81+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
82+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")

0 commit comments

Comments
 (0)