Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6e79bd

Browse filesBrowse files
committed
subplots can have titles now
1 parent bca7620 commit f6e79bd
Copy full SHA for f6e79bd

File tree

Expand file treeCollapse file tree

2 files changed

+34
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-4
lines changed

‎fastplotlib/layouts/_subplot.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_subplot.py
+32-3Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ._base import PlotArea
1212
from .. import graphics
13+
from ..graphics import TextGraphic
1314
from ._defaults import create_camera, create_controller
1415

1516

@@ -82,12 +83,40 @@ def __init__(
8283
graphic_cls_name = graphic_cls_name.lower().replace("graphic", "").replace("collection", "_collection")
8384
setattr(self, f"add_{graphic_cls_name}", pfunc)
8485

86+
self._title_graphic: TextGraphic = None
87+
if self.name is not None:
88+
self.set_title(self.name)
89+
8590
def _create_graphic(self, graphic_class, *args, **kwargs):
8691
graphic = graphic_class(*args, **kwargs)
8792
self.add_graphic(graphic, center=False)
8893

8994
return graphic
9095

96+
def set_title(self, text: Any):
97+
if text is None:
98+
return
99+
100+
text = str(text)
101+
if self._title_graphic is not None:
102+
self._title_graphic.update_text(text)
103+
else:
104+
tg = TextGraphic(text)
105+
self._title_graphic = tg
106+
107+
self.docked_viewports["top"].size = 25
108+
self.docked_viewports["top"].add_graphic(tg)
109+
110+
self._title_graphic.world_object.position.set(0, -2, 0)
111+
112+
def center_title(self):
113+
if self._title_graphic is None:
114+
raise AttributeError("No title graphic is set")
115+
116+
self._title_graphic.world_object.position.set(0, 0, 0)
117+
self.docked_viewports["top"].center_graphic(self._title_graphic)
118+
self._title_graphic.world_object.position.y = -2
119+
91120
def get_rect(self):
92121
row_ix, col_ix = self.position
93122
width_canvas, height_canvas = self.renderer.logical_size
@@ -171,9 +200,9 @@ def __init__(
171200
renderer=parent.renderer
172201
)
173202

174-
self.scene.add(
175-
Background(None, BackgroundMaterial((0.2, 0.0, 0, 1), (0, 0.0, 0.2, 1)))
176-
)
203+
# self.scene.add(
204+
# Background(None, BackgroundMaterial((0.2, 0.0, 0, 1), (0, 0.0, 0.2, 1)))
205+
# )
177206

178207
@property
179208
def size(self) -> int:

‎fastplotlib/widgets/image.py

Copy file name to clipboardExpand all lines: fastplotlib/widgets/image.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def __init__(
513513
min=minmax[0] - data_range_30p,
514514
max=minmax[1] + data_range_30p,
515515
step=data_range / 150,
516-
description=f"mm ['{name_slider}']",
516+
description=f"mm: {name_slider}",
517517
readout=True,
518518
readout_format='.3f',
519519
)
@@ -535,6 +535,7 @@ def __init__(
535535
ig = ImageGraphic(frame, **_kwargs)
536536
subplot.add_graphic(ig)
537537
subplot.name = name
538+
subplot.set_title(name)
538539
self.image_graphics.append(ig)
539540

540541
self.plot.renderer.add_event_handler(self._set_slider_layout, "resize")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.