Skip to content

Commit 32ea826

Browse files
authored
remove graphic suffix (#882)
* remove graphic suffix * update quickstart * replace dstack w column stack
1 parent dac31cf commit 32ea826

31 files changed

+211
-212
lines changed

examples/events/drag_points.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
figure = fpl.Figure(size=(700, 560))
2424

2525
# add a line
26-
line_graphic = figure[0, 0].add_line(data)
26+
line = figure[0, 0].add_line(data)
2727

2828
# add a scatter, share the line graphic buffer!
29-
scatter_graphic = figure[0, 0].add_scatter(data=line_graphic.data, sizes=25, colors="r")
29+
scatter = figure[0, 0].add_scatter(data=line.data, sizes=25, colors="r")
3030

3131
is_moving = False
3232
vertex_index = None
3333

3434

35-
@scatter_graphic.add_event_handler("pointer_down")
35+
@scatter.add_event_handler("pointer_down")
3636
def start_drag(ev: pygfx.PointerEvent):
3737
global is_moving
3838
global vertex_index
@@ -42,7 +42,7 @@ def start_drag(ev: pygfx.PointerEvent):
4242

4343
is_moving = True
4444
vertex_index = ev.pick_info["vertex_index"]
45-
scatter_graphic.colors[vertex_index] = "cyan"
45+
scatter.colors[vertex_index] = "cyan"
4646

4747

4848
@figure.renderer.add_event_handler("pointer_move")
@@ -63,13 +63,13 @@ def move_point(ev):
6363
if pos is None:
6464
# end movement
6565
is_moving = False
66-
scatter_graphic.colors[vertex_index] = "r" # reset color
66+
scatter.colors[vertex_index] = "r" # reset color
6767
vertex_index = None
6868
return
6969

7070
# change scatter data
7171
# since we are sharing the buffer, the line data will also change
72-
scatter_graphic.data[vertex_index, :-1] = pos[:-1]
72+
scatter.data[vertex_index, :-1] = pos[:-1]
7373

7474
# re-enable controller
7575
figure[0, 0].controller.enabled = True
@@ -83,7 +83,7 @@ def end_drag(ev: pygfx.PointerEvent):
8383
# end movement
8484
if is_moving:
8585
# reset color
86-
scatter_graphic.colors[vertex_index] = "r"
86+
scatter.colors[vertex_index] = "r"
8787

8888
is_moving = False
8989
vertex_index = None

examples/events/image_click.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
figure = fpl.Figure(size=(700, 560))
1919

2020
# create image graphic
21-
image_graphic = figure[0, 0].add_image(data=data)
21+
image = figure[0, 0].add_image(data=data)
2222

2323
# show the plot
2424
figure.show()
2525

2626

2727
# adding a click event, we can also use decorators to add event handlers
28-
@image_graphic.add_event_handler("click")
28+
@image.add_event_handler("click")
2929
def click_event(ev: pygfx.PointerEvent):
3030
# get the click location in screen coordinates
3131
xy = (ev.x, ev.y)

examples/events/line_data_thickness_event.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
xs = np.linspace(0, 4 * np.pi, 100)
1717
# sine wave
1818
ys = np.sin(xs)
19-
sine = np.column_stack([xs, ys])
19+
sine_data = np.column_stack([xs, ys])
2020

2121
# cosine wave
2222
ys = np.cos(xs)
23-
cosine = np.column_stack([xs, ys])
23+
cosine_data = np.column_stack([xs, ys])
2424

2525
# create line graphics
26-
sine_graphic = figure[0, 0].add_line(data=sine)
27-
cosine_graphic = figure[0, 0].add_line(data=cosine, offset=(0, 4, 0))
26+
sine = figure[0, 0].add_line(data=sine_data)
27+
cosine = figure[0, 0].add_line(data=cosine_data, offset=(0, 4, 0))
2828

2929
# make a list of the line graphics for convenience
30-
lines = [sine_graphic, cosine_graphic]
30+
lines = [sine, cosine]
3131

3232

3333
def change_thickness(ev: fpl.GraphicFeatureEvent):
@@ -66,11 +66,11 @@ def change_data(ev: fpl.GraphicFeatureEvent):
6666
# set the y-value of the middle 40 points of the sine graphic to 1
6767
# after the sine_graphic sets its data, the event handlers will be called
6868
# and therefore the cosine graphic will also set its data using the event data
69-
sine_graphic.data[30:70, 1] = np.ones(40)
69+
sine.data[30:70, 1] = np.ones(40)
7070

7171
# set the thickness of the cosine graphic, this will trigger an event
7272
# that causes the sine graphic's thickness to also be set from this value
73-
cosine_graphic.thickness = 10
73+
cosine.thickness = 10
7474

7575
# NOTE: fpl.loop.run() should not be used for interactive sessions
7676
# See the "JupyterLab and IPython" section in the user guide

examples/gridplot/multigraphic_gridplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
8484
xs = np.linspace(-10, 10, 100)
8585
# sine wave
8686
ys = np.sin(xs)
87-
sine = np.dstack([xs, ys])[0]
87+
sine = np.column_stack([xs, ys])
8888

8989
# make 10 identical waves
9090
sine_waves = 10 * [sine]

examples/guis/sine_cosine_funcs.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,55 +61,55 @@ def make_circle(center, radius: float, p, q, n_points: int) -> np.ndarray:
6161

6262
# create sine and cosine data
6363
xs = np.linspace(0, 2 * np.pi, 360)
64-
sine = np.sin(xs * P)
65-
cosine = np.cos(xs * Q)
64+
sine_data = np.sin(xs * P)
65+
cosine_data = np.cos(xs * Q)
6666

6767
# circle data
6868
circle_data = make_circle(center=(0, 0), p=P, q=Q, radius=1, n_points=360)
6969

7070
# make the circle line graphic, set the cmap transform using the sine function
71-
circle_graphic = figure["circle"].add_line(
72-
circle_data, thickness=4, cmap="bwr", cmap_transform=sine
71+
circle = figure["circle"].add_line(
72+
circle_data, thickness=4, cmap="bwr", cmap_transform=sine_data
7373
)
7474

7575
# line to show the circle radius
7676
# use it to indicate the current position of the sine and cosine selctors (below)
7777
radius_data = np.array([[0, 0, 0], [*circle_data[0], 0]])
78-
circle_radius_graphic = figure["circle"].add_line(
78+
circle_radius = figure["circle"].add_line(
7979
radius_data, thickness=6, colors="magenta"
8080
)
8181

8282
# sine line graphic, cmap transform set from the sine function
83-
sine_graphic = figure["sin"].add_line(
84-
sine, thickness=10, cmap="bwr", cmap_transform=sine
83+
sine = figure["sin"].add_line(
84+
sine_data, thickness=10, cmap="bwr", cmap_transform=sine_data
8585
)
8686

8787
# cosine line graphic, cmap transform set from the sine function
8888
# illustrates the sine function values on the cosine graphic
89-
cosine_graphic = figure["cos"].add_line(
90-
cosine, thickness=10, cmap="bwr", cmap_transform=sine
89+
cosine = figure["cos"].add_line(
90+
cosine_data, thickness=10, cmap="bwr", cmap_transform=sine_data
9191
)
9292

9393
# add linear selectors to the sine and cosine line graphics
94-
sine_selector = sine_graphic.add_linear_selector()
95-
cosine_selector = cosine_graphic.add_linear_selector()
94+
sine_selector = sine.add_linear_selector()
95+
cosine_selector = cosine.add_linear_selector()
9696

9797

9898
def set_circle_cmap(ev):
9999
# sets the cmap transforms
100100

101101
cmap_transform = ev.graphic.data[:, 1] # y-val data of the sine or cosine graphic
102-
for g in [sine_graphic, cosine_graphic]:
102+
for g in [sine, cosine]:
103103
g.cmap.transform = cmap_transform
104104

105105
# set circle cmap transform
106-
circle_graphic.cmap.transform = cmap_transform
106+
circle.cmap.transform = cmap_transform
107107

108108
# when the sine or cosine graphic is clicked, the cmap_transform
109109
# of the sine, cosine and circle line graphics are all set from
110110
# the y-values of the clicked line
111-
sine_graphic.add_event_handler(set_circle_cmap, "click")
112-
cosine_graphic.add_event_handler(set_circle_cmap, "click")
111+
sine.add_event_handler(set_circle_cmap, "click")
112+
cosine.add_event_handler(set_circle_cmap, "click")
113113

114114

115115
def set_x_val(ev):
@@ -120,7 +120,7 @@ def set_x_val(ev):
120120
sine_selector.selection = value
121121
cosine_selector.selection = value
122122

123-
circle_radius_graphic.data[1, :-1] = circle_data[index]
123+
circle_radius.data[1, :-1] = circle_data[index]
124124

125125
# add same event handler to both graphics
126126
sine_selector.add_event_handler(set_x_val, "selection")
@@ -138,19 +138,19 @@ def __init__(self, figure, size, location, title):
138138
self._q = 1
139139

140140
def _set_data(self):
141-
global sine_graphic, cosine_graphic, circle_graphic, circle_radius_graphic, circle_data
141+
global sine, cosine, circle, circle_radius, circle_data
142142

143143
# make new data
144-
sine = np.sin(xs * self._p)
145-
cosine = np.cos(xs * self._q)
144+
sine_data = np.sin(xs * self._p)
145+
cosine_data = np.cos(xs * self._q)
146146
circle_data = make_circle(center=(0, 0), p=self._p, q=self._q, radius=1, n_points=360)
147147

148148

149149
# set the graphics
150-
sine_graphic.data[:, 1] = sine
151-
cosine_graphic.data[:, 1] = cosine
152-
circle_graphic.data[:, :2] = circle_data
153-
circle_radius_graphic.data[1, :-1] = circle_data[sine_selector.get_selected_index()]
150+
sine.data[:, 1] = sine_data
151+
cosine.data[:, 1] = cosine_data
152+
circle.data[:, :2] = circle_data
153+
circle_radius.data[1, :-1] = circle_data[sine_selector.get_selected_index()]
154154

155155
def update(self):
156156
flag_set_data = False

examples/heatmap/heatmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
data = np.vstack([sine * i for i in range(2_300)])
2222

2323
# plot the image data
24-
img = figure[0, 0].add_image(data=data, name="heatmap")
24+
image = figure[0, 0].add_image(data=data, name="heatmap")
2525
del data
2626

2727
figure.show()

examples/image/image_cmap.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88
# test_example = true
99
# sphinx_gallery_pygfx_docs = 'screenshot'
1010

11-
import fastplotlib as fpl
1211
import imageio.v3 as iio
1312

13+
import fastplotlib as fpl
14+
1415
im = iio.imread("imageio:camera.png")
1516

1617
figure = fpl.Figure(size=(700, 560))
1718

1819
# plot the image data
19-
image_graphic = figure[0, 0].add_image(data=im, name="random-image")
20+
image = figure[0, 0].add_image(data=im, name="random-image")
2021

2122
figure.show()
2223

23-
image_graphic.cmap = "viridis"
24+
image.cmap = "viridis"
2425

2526
# NOTE: fpl.loop.run() should not be used for interactive sessions
2627
# See the "JupyterLab and IPython" section in the user guide

examples/image/image_rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
figure = fpl.Figure(size=(700, 560))
1717

1818
# plot the image data
19-
image_graphic = figure[0, 0].add_image(data=im, name="iio astronaut")
19+
image = figure[0, 0].add_image(data=im, name="iio astronaut")
2020

2121
figure.show()
2222

examples/image/image_rgbvminvmax.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
figure = fpl.Figure(size=(700, 560))
1717

1818
# plot the image data
19-
image_graphic = figure[0, 0].add_image(data=im, name="iio astronaut")
19+
image = figure[0, 0].add_image(data=im, name="iio astronaut")
2020

2121
figure.show()
2222

23-
image_graphic.vmin = 0.5
24-
image_graphic.vmax = 0.75
23+
image.vmin = 0.5
24+
image.vmax = 0.75
2525

2626
# NOTE: fpl.loop.run() should not be used for interactive sessions
2727
# See the "JupyterLab and IPython" section in the user guide

examples/image/image_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
data = iio.imread("imageio:camera.png")
1717

1818
# plot the image data
19-
image_graphic = figure[0, 0].add_image(data=data, name="iio camera")
19+
image = figure[0, 0].add_image(data=data, name="iio camera")
2020

2121
figure.show()
2222

0 commit comments

Comments
 (0)