Skip to content

remove graphic suffix #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/events/drag_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
figure = fpl.Figure(size=(700, 560))

# add a line
line_graphic = figure[0, 0].add_line(data)
line = figure[0, 0].add_line(data)

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

is_moving = False
vertex_index = None


@scatter_graphic.add_event_handler("pointer_down")
@scatter.add_event_handler("pointer_down")
def start_drag(ev: pygfx.PointerEvent):
global is_moving
global vertex_index
Expand All @@ -42,7 +42,7 @@ def start_drag(ev: pygfx.PointerEvent):

is_moving = True
vertex_index = ev.pick_info["vertex_index"]
scatter_graphic.colors[vertex_index] = "cyan"
scatter.colors[vertex_index] = "cyan"


@figure.renderer.add_event_handler("pointer_move")
Expand All @@ -63,13 +63,13 @@ def move_point(ev):
if pos is None:
# end movement
is_moving = False
scatter_graphic.colors[vertex_index] = "r" # reset color
scatter.colors[vertex_index] = "r" # reset color
vertex_index = None
return

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

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

is_moving = False
vertex_index = None
Expand Down
4 changes: 2 additions & 2 deletions examples/events/image_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
figure = fpl.Figure(size=(700, 560))

# create image graphic
image_graphic = figure[0, 0].add_image(data=data)
image = figure[0, 0].add_image(data=data)

# show the plot
figure.show()


# adding a click event, we can also use decorators to add event handlers
@image_graphic.add_event_handler("click")
@image.add_event_handler("click")
def click_event(ev: pygfx.PointerEvent):
# get the click location in screen coordinates
xy = (ev.x, ev.y)
Expand Down
14 changes: 7 additions & 7 deletions examples/events/line_data_thickness_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
xs = np.linspace(0, 4 * np.pi, 100)
# sine wave
ys = np.sin(xs)
sine = np.column_stack([xs, ys])
sine_data = np.column_stack([xs, ys])

# cosine wave
ys = np.cos(xs)
cosine = np.column_stack([xs, ys])
cosine_data = np.column_stack([xs, ys])

# create line graphics
sine_graphic = figure[0, 0].add_line(data=sine)
cosine_graphic = figure[0, 0].add_line(data=cosine, offset=(0, 4, 0))
sine = figure[0, 0].add_line(data=sine_data)
cosine = figure[0, 0].add_line(data=cosine_data, offset=(0, 4, 0))

# make a list of the line graphics for convenience
lines = [sine_graphic, cosine_graphic]
lines = [sine, cosine]


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

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

# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
Expand Down
2 changes: 1 addition & 1 deletion examples/gridplot/multigraphic_gridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
xs = np.linspace(-10, 10, 100)
# sine wave
ys = np.sin(xs)
sine = np.dstack([xs, ys])[0]
sine = np.column_stack([xs, ys])

# make 10 identical waves
sine_waves = 10 * [sine]
Expand Down
46 changes: 23 additions & 23 deletions examples/guis/sine_cosine_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,55 @@ def make_circle(center, radius: float, p, q, n_points: int) -> np.ndarray:

# create sine and cosine data
xs = np.linspace(0, 2 * np.pi, 360)
sine = np.sin(xs * P)
cosine = np.cos(xs * Q)
sine_data = np.sin(xs * P)
cosine_data = np.cos(xs * Q)

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

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

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

# sine line graphic, cmap transform set from the sine function
sine_graphic = figure["sin"].add_line(
sine, thickness=10, cmap="bwr", cmap_transform=sine
sine = figure["sin"].add_line(
sine_data, thickness=10, cmap="bwr", cmap_transform=sine_data
)

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

# add linear selectors to the sine and cosine line graphics
sine_selector = sine_graphic.add_linear_selector()
cosine_selector = cosine_graphic.add_linear_selector()
sine_selector = sine.add_linear_selector()
cosine_selector = cosine.add_linear_selector()


def set_circle_cmap(ev):
# sets the cmap transforms

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

# set circle cmap transform
circle_graphic.cmap.transform = cmap_transform
circle.cmap.transform = cmap_transform

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


def set_x_val(ev):
Expand All @@ -120,7 +120,7 @@ def set_x_val(ev):
sine_selector.selection = value
cosine_selector.selection = value

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

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

def _set_data(self):
global sine_graphic, cosine_graphic, circle_graphic, circle_radius_graphic, circle_data
global sine, cosine, circle, circle_radius, circle_data

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


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

def update(self):
flag_set_data = False
Expand Down
2 changes: 1 addition & 1 deletion examples/heatmap/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
data = np.vstack([sine * i for i in range(2_300)])

# plot the image data
img = figure[0, 0].add_image(data=data, name="heatmap")
image = figure[0, 0].add_image(data=data, name="heatmap")
del data

figure.show()
Expand Down
7 changes: 4 additions & 3 deletions examples/image/image_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio

import fastplotlib as fpl

im = iio.imread("imageio:camera.png")

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

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

figure.show()

image_graphic.cmap = "viridis"
image.cmap = "viridis"

# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
Expand Down
2 changes: 1 addition & 1 deletion examples/image/image_rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
figure = fpl.Figure(size=(700, 560))

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

figure.show()

Expand Down
6 changes: 3 additions & 3 deletions examples/image/image_rgbvminvmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
figure = fpl.Figure(size=(700, 560))

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

figure.show()

image_graphic.vmin = 0.5
image_graphic.vmax = 0.75
image.vmin = 0.5
image.vmax = 0.75

# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
Expand Down
2 changes: 1 addition & 1 deletion examples/image/image_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
data = iio.imread("imageio:camera.png")

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

figure.show()

Expand Down
2 changes: 1 addition & 1 deletion examples/image/image_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[[0, 1, 2],
[3, 4, 5]]
)
image_graphic = figure[0, 0].add_image(data)
image = figure[0, 0].add_image(data)

figure.show()

Expand Down
6 changes: 3 additions & 3 deletions examples/image/image_vminvmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
data = iio.imread("imageio:astronaut.png")

# plot the image data
image_graphic = figure[0, 0].add_image(data=data, name="iio astronaut")
image = figure[0, 0].add_image(data=data, name="iio astronaut")

figure.show()

image_graphic.vmin = 0.5
image_graphic.vmax = 0.75
image.vmin = 0.5
image.vmax = 0.75

# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
Expand Down
12 changes: 6 additions & 6 deletions examples/line/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
xs = np.linspace(-10, 10, 100)
# sine wave
ys = np.sin(xs)
sine = np.dstack([xs, ys])[0]
sine_data = np.column_stack([xs, ys])

# cosine wave
ys = np.cos(xs) + 5
cosine = np.dstack([xs, ys])[0]
cosine_data = np.column_stack([xs, ys])

# sinc function
a = 0.5
ys = np.sinc(xs) * 3 + 8
sinc = np.dstack([xs, ys])[0]
sinc_data = np.column_stack([xs, ys])

sine_graphic = figure[0, 0].add_line(data=sine, thickness=5, colors="magenta")
sine = figure[0, 0].add_line(data=sine_data, thickness=5, colors="magenta")

# you can also use colormaps for lines!
cosine_graphic = figure[0, 0].add_line(data=cosine, thickness=12, cmap="autumn")
cosine = figure[0, 0].add_line(data=cosine_data, thickness=12, cmap="autumn")

# or a list of colors for each datapoint
colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25
sinc_graphic = figure[0, 0].add_line(data=sinc, thickness=5, colors=colors)
sinc = figure[0, 0].add_line(data=sinc_data, thickness=5, colors=colors)

figure[0, 0].axes.grids.xy.visible = True
figure.show()
Expand Down
14 changes: 7 additions & 7 deletions examples/line/line_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
xs = np.linspace(-10, 10, 100)
# sine wave
ys = np.sin(xs)
sine = np.dstack([xs, ys])[0]
sine_data = np.column_stack([xs, ys])

# cosine wave
ys = np.cos(xs) - 5
cosine = np.dstack([xs, ys])[0]
cosine_data = np.column_stack([xs, ys])

# cmap_transform from an array, so the colors on the sine line will be based on the sine y-values
sine_graphic = figure[0, 0].add_line(
data=sine,
sine = figure[0, 0].add_line(
data=sine_data,
thickness=10,
cmap="plasma",
cmap_transform=sine[:, 1]
cmap_transform=sine_data[:, 1]
)

# qualitative colormaps, useful for cluster labels or other types of categorical labels
labels = [0] * 25 + [5] * 10 + [1] * 35 + [2] * 30
cosine_graphic = figure[0, 0].add_line(
data=cosine,
cosine = figure[0, 0].add_line(
data=cosine_data,
thickness=10,
cmap="tab10",
cmap_transform=labels
Expand Down
Loading
Loading