Skip to content

Commit b4653b8

Browse files
feat(plotly): implement gauge-basic (#9531)
## Implementation: `gauge-basic` - python/plotly Implements the **python/plotly** version of `gauge-basic`. **File:** `plots/gauge-basic/implementations/python/plotly.py` **Parent Issue:** #857 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/28476584859)* --------- 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 79dc43f commit b4653b8

2 files changed

Lines changed: 140 additions & 101 deletions

File tree

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" anyplot.ai
22
gauge-basic: Basic Gauge Chart
3-
Library: plotly 6.7.0 | Python 3.14.4
4-
Quality: 94/100 | Updated: 2026-04-25
3+
Library: plotly 6.8.0 | Python 3.13.14
4+
Quality: 94/100 | Updated: 2026-06-30
55
"""
66

77
import os
@@ -17,42 +17,53 @@
1717
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
1818
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"
1919

20-
# Okabe-Ito colorblind-safe stand-ins for the red/amber/green convention
21-
ZONE_LOW = "#AE3030" # imprint red — bad
22-
ZONE_MID = "#DDCC77" # imprint amber — caution
23-
ZONE_HIGH = "#009E73" # imprint green — good
20+
# Imprint palette zone colors: red=bad, amber=caution, green=good
21+
ZONE_LOW = "#AE3030" # Imprint matte red — At Risk
22+
ZONE_MID = "#DDCC77" # Imprint amber — On Track
23+
ZONE_HIGH = "#009E73" # Imprint brand green — Exceeds Target
2424

2525
# Data — Sales target achievement for the quarter
2626
value = 72
2727
min_value = 0
2828
max_value = 100
2929
thresholds = [30, 70]
3030

31+
goal = thresholds[1]
32+
3133
# Plot
3234
fig = go.Figure(
3335
go.Indicator(
34-
mode="gauge+number",
36+
mode="gauge+number+delta",
3537
value=value,
36-
number={"font": {"size": 96, "color": INK}, "suffix": "%"},
38+
number={"font": {"size": 48, "color": INK, "family": "Arial"}, "suffix": "%"},
39+
delta={
40+
"reference": goal,
41+
"relative": False,
42+
"valueformat": "+.0f",
43+
"suffix": "pp vs. goal",
44+
"font": {"size": 13, "color": INK, "family": "Arial"},
45+
"increasing": {"color": ZONE_HIGH},
46+
"decreasing": {"color": ZONE_LOW},
47+
},
3748
title={
3849
"text": (
3950
"<b>Sales Target Achievement</b>"
40-
f"<br><span style='font-size:22px;color:{INK_SOFT}'>"
41-
"gauge-basic · plotly · anyplot.ai</span>"
51+
f"<br><span style='font-size:11px;color:{INK_SOFT}'>"
52+
"gauge-basic · python · plotly · anyplot.ai</span>"
4253
),
43-
"font": {"size": 32, "color": INK},
54+
"font": {"size": 16, "color": INK, "family": "Arial"},
4455
},
4556
gauge={
4657
"shape": "angular",
4758
"axis": {
4859
"range": [min_value, max_value],
49-
"tickwidth": 2,
60+
"tickwidth": 1,
5061
"tickcolor": INK_SOFT,
51-
"tickfont": {"size": 18, "color": INK_SOFT},
62+
"tickfont": {"size": 10, "color": INK_SOFT, "family": "Arial"},
5263
"ticksuffix": "%",
5364
"dtick": 10,
5465
},
55-
# Slim needle-style indicator so the zone colors stay visible
66+
# Slim needle keeps zone colors fully visible
5667
"bar": {"color": INK, "thickness": 0.06, "line": {"color": INK, "width": 0}},
5768
"bgcolor": ELEVATED_BG,
5869
"borderwidth": 1,
@@ -62,18 +73,19 @@
6273
{"range": [thresholds[0], thresholds[1]], "color": ZONE_MID},
6374
{"range": [thresholds[1], max_value], "color": ZONE_HIGH},
6475
],
65-
"threshold": {"line": {"color": INK, "width": 5}, "thickness": 0.95, "value": value},
76+
"threshold": {"line": {"color": INK, "width": 3}, "thickness": 0.95, "value": value},
6677
},
6778
domain={"x": [0.05, 0.95], "y": [0.30, 0.95]},
6879
)
6980
)
7081

71-
# Layout — page surface + zone legend + target-exceeded callout
82+
# Layout — page surface + zone legend + callout
7283
fig.update_layout(
7384
paper_bgcolor=PAGE_BG,
7485
plot_bgcolor=PAGE_BG,
7586
font={"family": "Arial", "color": INK},
76-
margin={"l": 80, "r": 80, "t": 140, "b": 120},
87+
autosize=False,
88+
margin={"l": 40, "r": 40, "t": 70, "b": 60},
7789
annotations=[
7890
# Zone legend row — three color-coded chips below the gauge
7991
{
@@ -82,56 +94,56 @@
8294
"xref": "paper",
8395
"yref": "paper",
8496
"text": (
85-
f"<span style='color:{ZONE_LOW};font-size:24px'>●</span> "
97+
f"<span style='color:{ZONE_LOW};font-size:13px'>●</span> "
8698
f"<b>At Risk</b> "
8799
f"<span style='color:{INK_MUTED}'>0–30%</span>"
88100
),
89101
"showarrow": False,
90-
"font": {"size": 18, "color": INK},
102+
"font": {"size": 12, "color": INK, "family": "Arial"},
91103
},
92104
{
93105
"x": 0.50,
94106
"y": 0.14,
95107
"xref": "paper",
96108
"yref": "paper",
97109
"text": (
98-
f"<span style='color:{ZONE_MID};font-size:24px'>●</span> "
110+
f"<span style='color:{ZONE_MID};font-size:13px'>●</span> "
99111
f"<b>On Track</b> "
100112
f"<span style='color:{INK_MUTED}'>30–70%</span>"
101113
),
102114
"showarrow": False,
103-
"font": {"size": 18, "color": INK},
115+
"font": {"size": 12, "color": INK, "family": "Arial"},
104116
},
105117
{
106118
"x": 0.80,
107119
"y": 0.14,
108120
"xref": "paper",
109121
"yref": "paper",
110122
"text": (
111-
f"<span style='color:{ZONE_HIGH};font-size:24px'>●</span> "
123+
f"<span style='color:{ZONE_HIGH};font-size:13px'>●</span> "
112124
f"<b>Exceeds Target</b> "
113125
f"<span style='color:{INK_MUTED}'>70–100%</span>"
114126
),
115127
"showarrow": False,
116-
"font": {"size": 18, "color": INK},
128+
"font": {"size": 12, "color": INK, "family": "Arial"},
117129
},
118-
# Target-exceeded callout — emphasises the threshold-crossing story
130+
# Target-exceeded callout — immediate data story
119131
{
120132
"x": 0.5,
121-
"y": 0.02,
133+
"y": 0.03,
122134
"xref": "paper",
123135
"yref": "paper",
124136
"text": "<b>✓ Target Exceeded</b> · 72% surpasses the 70% goal",
125137
"showarrow": False,
126-
"font": {"size": 22, "color": ZONE_HIGH},
138+
"font": {"size": 12, "color": ZONE_HIGH, "family": "Arial"},
127139
"bgcolor": ELEVATED_BG,
128140
"bordercolor": ZONE_HIGH,
129-
"borderwidth": 2,
130-
"borderpad": 12,
141+
"borderwidth": 1,
142+
"borderpad": 6,
131143
},
132144
],
133145
)
134146

135147
# Save
136-
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
148+
fig.write_image(f"plot-{THEME}.png", width=800, height=450, scale=4)
137149
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")

0 commit comments

Comments
 (0)