Skip to content

Commit 00a11d5

Browse files
committed
New Feature: Add various marker types including arrows, ellipses, rectangles, squares, polygons, texts, points, horizontal lines, and vertical lines for enhanced plotting capabilities
1 parent fd6bfb6 commit 00a11d5

25 files changed

Lines changed: 219 additions & 37 deletions

Examples/Interactive/plot_interactive_fft.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ def _compute_fft(img_full, x0, y0, w, h):
147147

148148
# ── Callbacks ─────────────────────────────────────────────────────────────────
149149

150-
@v_real.on_change(wid)
150+
@wid.on_changed
151151
def _roi_dragging(event):
152152
"""Fires on every drag frame — highlight rectangle while dragging."""
153153
# Cheaply pulse the widget colour to give live drag feedback.
154154
for w in v_real._state["overlay_widgets"]:
155-
if w["id"] == wid:
155+
if w["id"] == wid._id:
156156
w["color"] = "#ff9800" # orange while dragging
157157
break
158158
v_real._push()
159159

160160

161-
@v_real.on_release(wid)
161+
@wid.on_release
162162
def _roi_released(event):
163163
"""Fires once on mouse-up — recompute and push the full FFT."""
164164
x0 = event.data.get("x", roi_x0)
@@ -168,14 +168,14 @@ def _roi_released(event):
168168

169169
# Restore widget colour to yellow
170170
for widget in v_real._state["overlay_widgets"]:
171-
if widget["id"] == wid:
171+
if widget["id"] == wid._id:
172172
widget["color"] = "#ffeb3b"
173173
break
174174

175175
log_mag, freq_x, freq_y = _compute_fft(image, x0, y0, w, h)
176176

177177
# Push updated FFT into the right panel
178-
v_fft.update(log_mag, x_axis=freq_x, y_axis=freq_y, units="1/Å")
178+
v_fft.update(log_mag, x_axis=freq_x, y_axis=freq_y, units="1/\u00c5")
179179

180180

181181
fig

Examples/Markers/plot_arrows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
tails = rng.uniform(15, 100, (8, 2))
2121
U = rng.uniform(-18, 18, 8)
2222
V = rng.uniform(-18, 18, 8)
23-
2423
v.add_arrows(tails, U, V, name="flow",
2524
edgecolors="#76ff03", linewidths=2.0,
2625
label="flow vectors")
26+
2727
fig
2828

2929
# %%

Examples/Markers/plot_circles.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
"""
22
Circles
33
=======
4+
45
Mark circular features on a 2-D image with
56
:meth:`~anyplotlib.figure_plots.Plot2D.add_circles`.
67
Use ``markers["circles"]["name"].set(...)`` to update them live.
78
"""
89
import numpy as np
910
import anyplotlib as vw
11+
1012
rng = np.random.default_rng(0)
1113
data = rng.standard_normal((128, 128)).cumsum(0).cumsum(1)
1214
data = (data - data.min()) / (data.max() - data.min())
1315
xy = np.linspace(0, 10, 128)
16+
1417
fig, ax = vw.subplots(1, 1, figsize=(460, 460))
1518
v = ax.imshow(data, axes=[xy, xy], units="nm")
19+
1620
centres = rng.uniform(15, 113, (8, 2))
1721
v.add_circles(centres, name="spots", radius=10,
1822
edgecolors="#ff1744", facecolors="#ff174433",
1923
labels=[f"#{i}" for i in range(8)])
24+
2025
fig
26+
2127
# %%
2228
# Live update
2329
# -----------
2430
# Call ``.set()`` on the marker group to push any change immediately.
31+
2532
v.markers["circles"]["spots"].set(radius=16, edgecolors="#ffcc00",
2633
facecolors="#ffcc0033")
2734
fig

Examples/Markers/plot_ellipses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
name="grains",
2424
edgecolors="#ff9100", facecolors="#ff910033",
2525
label="grains", labels=["A", "B", "C"])
26+
2627
fig
2728

2829
# %%
@@ -34,4 +35,3 @@
3435
edgecolors="#69f0ae",
3536
facecolors="#69f0ae33")
3637
fig
37-
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
"""
22
Horizontal Lines
33
================
4-
Draw read-only horizontal lines on a 1-D plot with
4+
5+
Draw static horizontal threshold lines on a 1-D plot with
56
:meth:`~anyplotlib.figure_plots.Plot1D.add_hlines`.
67
Use ``markers["hlines"]["name"].set(...)`` to update them live.
78
"""
89
import numpy as np
910
import anyplotlib as vw
11+
1012
x = np.linspace(0, 4 * np.pi, 512)
1113
signal = np.sin(x)
14+
1215
fig, ax = vw.subplots(1, 1, figsize=(560, 300))
1316
v = ax.plot(signal, axes=[x], units="rad")
17+
1418
v.add_hlines([0.5, 0.0, -0.5], name="thresholds",
1519
color="#69f0ae", linewidths=1.5,
1620
label="thresholds", labels=["+0.5", "zero", "-0.5"])
21+
1722
fig
23+
1824
# %%
1925
# Live update
2026
# -----------
27+
2128
v.markers["hlines"]["thresholds"].set(color="#ff1744", linewidths=2.0)
2229
fig

Examples/Markers/plot_line_segments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
edgecolors="#00e5ff", linewidths=1.5,
2929
label="frame",
3030
labels=["top", "right", "bottom", "left", "diagonal"])
31+
3132
fig
3233

3334
# %%

Examples/Markers/plot_points.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
"""
22
Points
33
======
4-
Draw point markers on a 1-D plot with
4+
5+
Mark specific (x, y) positions on a 1-D plot with
56
:meth:`~anyplotlib.figure_plots.Plot1D.add_points`.
67
Use ``markers["points"]["name"].set(...)`` to update them live.
78
"""
89
import numpy as np
910
import anyplotlib as vw
11+
1012
x = np.linspace(0, 4 * np.pi, 512)
1113
signal = np.sin(x)
14+
1215
fig, ax = vw.subplots(1, 1, figsize=(560, 300))
1316
v = ax.plot(signal, axes=[x], units="rad")
17+
1418
peak_x = np.array([np.pi / 2, 5 * np.pi / 2, 9 * np.pi / 2])
1519
offsets = np.column_stack([peak_x, np.sin(peak_x)])
1620
v.add_points(offsets, name="peaks",
17-
edgecolors="#ff1744", facecolors="#ff174433", sizes=8,
21+
sizes=8, color="#ff1744", facecolors="#ff174433",
1822
label="peaks", labels=["P1", "P2", "P3"])
23+
1924
fig
25+
2026
# %%
2127
# Live update
2228
# -----------
23-
v.markers["points"]["peaks"].set(sizes=12, edgecolors="#ffcc00",
29+
30+
v.markers["points"]["peaks"].set(sizes=12, color="#ffcc00",
2431
facecolors="#ffcc0033")
2532
fig

Examples/Markers/plot_polygons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
hexagon = [[64.0 + 28 * np.cos(np.radians(60 * k)),
2222
95.0 + 28 * np.sin(np.radians(60 * k))]
2323
for k in range(6)]
24-
2524
v.add_polygons([triangle, hexagon], name="shapes",
2625
edgecolors="#69f0ae", facecolors="#69f0ae22",
2726
linewidths=2.0,
2827
label="shapes", labels=["triangle", "hexagon"])
28+
2929
fig
3030

3131
# %%

Examples/Markers/plot_rectangles.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
"""
22
Rectangles
33
==========
4+
45
Draw bounding boxes on a 2-D image with
56
:meth:`~anyplotlib.figure_plots.Plot2D.add_rectangles`.
7+
Use ``markers["rectangles"]["name"].set(...)`` to update them live.
68
"""
79
import numpy as np
810
import anyplotlib as vw
11+
912
rng = np.random.default_rng(1)
1013
data = rng.standard_normal((128, 128)).cumsum(0).cumsum(1)
1114
data = (data - data.min()) / (data.max() - data.min())
1215
xy = np.linspace(0, 10, 128)
16+
1317
fig, ax = vw.subplots(1, 1, figsize=(460, 460))
1418
v = ax.imshow(data, axes=[xy, xy], units="nm")
19+
1520
centres = rng.uniform(20, 108, (5, 2))
1621
v.add_rectangles(centres, widths=22, heights=14, name="boxes",
1722
edgecolors="#00e5ff", facecolors="#00e5ff22",
1823
labels=[f"R{i}" for i in range(5)])
24+
1925
fig
26+
2027
# %%
2128
# Live update
2229
# -----------
30+
2331
v.markers["rectangles"]["boxes"].set(widths=30, heights=20,
2432
edgecolors="#ff9100",
2533
facecolors="#ff910033")

Examples/Markers/plot_squares.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
name="tiles",
2525
edgecolors="#00e5ff", facecolors="#00e5ff22",
2626
label="tiles", labels=[f"T{i}" for i in range(5)])
27+
2728
fig
2829

2930
# %%

0 commit comments

Comments
 (0)