Skip to content

Commit 5702277

Browse files
committed
Minor improvements
1 parent fae1c42 commit 5702277

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

docs/source/notebooks/circles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
fig = plot.plot_plotly(
9797
colors=labels,
9898
cmap=["jet", "viridis", "cividis"],
99+
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
99100
agg=np.nanmean,
100101
width=600,
101102
height=600,
@@ -118,6 +119,7 @@
118119
fig = plot.plot_plotly(
119120
colors=labels,
120121
cmap=["jet", "viridis", "cividis"],
122+
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
121123
agg=np.nanstd,
122124
width=600,
123125
height=600,

docs/source/notebooks/digits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def mode(arr):
103103
colors=labels,
104104
cmap=["jet", "viridis", "cividis"],
105105
agg=mode,
106+
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
106107
title="mode of digits",
107108
width=600,
108109
height=600,
109-
node_size=0.5,
110110
)
111111

112112
fig.show(config={"scrollZoom": True}, renderer="notebook_connected")
@@ -134,10 +134,10 @@ def entropy(arr):
134134
colors=labels,
135135
cmap=["jet", "viridis", "cividis"],
136136
agg=entropy,
137+
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
137138
title="entropy of digits",
138139
width=600,
139140
height=600,
140-
node_size=0.5,
141141
)
142142

143143
fig.show(config={"scrollZoom": True}, renderer="notebook_connected")

src/tdamapper/plot_backends/plot_plotly.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ def _get_plotly_colorscales():
5353
PLOTLY_CMAPS = _get_plotly_colorscales()
5454

5555

56+
class PlotlyUI:
57+
58+
def __init__(self):
59+
self.menu_cmap = None
60+
self.menu_color = None
61+
self.slider_size = None
62+
63+
def set_menu_cmap(self, mapper_plot, cmaps):
64+
cmaps_plotly = [PLOTLY_CMAPS.get(c.lower()) for c in cmaps]
65+
self.menu_cmap = _ui_cmap(mapper_plot, cmaps_plotly)
66+
67+
def set_menu_color(self, mapper_plot, colors, titles, agg):
68+
self.menu_color = _ui_color(mapper_plot, colors, titles, agg)
69+
70+
def set_slider_size(self, mapper_plot, node_sizes):
71+
self.slider_size = _ui_node_size(mapper_plot, node_sizes)
72+
73+
5674
def _to_cmaps(cmap: Union[str, List[str]]) -> List[str]:
5775
"""Convert a single cmap or a list of cmaps to a list of cmaps."""
5876
if isinstance(cmap, str):
@@ -488,32 +506,16 @@ def _layout():
488506
)
489507

490508

491-
class PlotlyUI:
492-
493-
def __init__(self):
494-
self.menu_cmap = None
495-
self.menu_color = None
496-
self.slider_size = None
497-
498-
def set_menu_cmap(self, mapper_plot, cmaps):
499-
cmaps_plotly = [PLOTLY_CMAPS.get(c.lower()) for c in cmaps]
500-
self.menu_cmap = _ui_cmap(mapper_plot, cmaps_plotly)
501-
502-
def set_menu_color(self, mapper_plot, colors, titles, agg):
503-
self.menu_color = _ui_color(mapper_plot, colors, titles, agg)
504-
505-
def set_slider_size(self, mapper_plot, node_sizes):
506-
self.slider_size = _ui_node_size(mapper_plot, node_sizes)
507-
508-
509509
def _set_ui(mapper_fig, plotly_ui: PlotlyUI):
510510
menus = []
511511
sliders = []
512+
x = 0.0
512513
if plotly_ui.menu_cmap:
513-
plotly_ui.menu_cmap["x"] = 0.25
514+
plotly_ui.menu_cmap["x"] = x
515+
x += 0.25
514516
menus.append(plotly_ui.menu_cmap)
515517
if plotly_ui.menu_color:
516-
plotly_ui.menu_color["x"] = 0.0
518+
plotly_ui.menu_color["x"] = x
517519
menus.append(plotly_ui.menu_color)
518520
if plotly_ui.slider_size:
519521
plotly_ui.slider_size["x"] = 0.0

0 commit comments

Comments
 (0)