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 32db614

Browse filesBrowse files
authored
allow getting and setting cmaps in image widget (#320)
1 parent d775408 commit 32db614
Copy full SHA for 32db614

File tree

1 file changed

+28
-0
lines changed
Filter options

1 file changed

+28
-0
lines changed

‎fastplotlib/widgets/image.py

Copy file name to clipboardExpand all lines: fastplotlib/widgets/image.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ def managed_graphics(self) -> List[ImageGraphic]:
113113
iw_managed.append(subplot["image_widget_managed"])
114114
return iw_managed
115115

116+
@property
117+
def cmap(self) -> List[str]:
118+
cmaps = list()
119+
for g in self.managed_graphics:
120+
cmaps.append(g.cmap.name)
121+
122+
return cmaps
123+
124+
@cmap.setter
125+
def cmap(self, names: Union[str, List[str]]):
126+
if isinstance(names, list):
127+
if not all([isinstance(n, str) for n in names]):
128+
raise TypeError(f"Must pass cmap name as a `str` of list of `str`, you have passed:\n{names}")
129+
130+
if not len(names) == len(self.managed_graphics):
131+
raise IndexError(
132+
f"If passing a list of cmap names, the length of the list must be the same as the number of "
133+
f"image widget subplots. You have passed: {len(names)} cmap names and have "
134+
f"{len(self.managed_graphics)} image widget subplots"
135+
)
136+
137+
for name, g in zip(names, self.managed_graphics):
138+
g.cmap = name
139+
140+
elif isinstance(names, str):
141+
for g in self.managed_graphics:
142+
g.cmap = names
143+
116144
@property
117145
def data(self) -> List[np.ndarray]:
118146
"""data currently displayed in the widget"""

0 commit comments

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