Skip to content

Commit 85408fb

Browse files
committed
Improved update method with graph and dim
1 parent 1776a41 commit 85408fb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/tdamapper/plot.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ def _update_layout(self):
325325
height=self.height)
326326

327327
def update(self,
328+
graph=None,
329+
dim=None,
328330
seed=None,
329331
iterations=None,
330332
colors=None,
@@ -340,6 +342,12 @@ def update(self,
340342
calling this method, the figure will be updated according to the supplied
341343
parameters.
342344
345+
:param graph: The precomputed Mapper graph to be embedded. This can be
346+
obtained by calling :func:`tdamapper.core.mapper_graph` or
347+
:func:`tdamapper.core.MapperAlgorithm.fit_transform`.
348+
:type graph: :class:`networkx.Graph`, required
349+
:param dim: The dimension of the graph embedding (2 or 3).
350+
:type dim: int
343351
:param seed: The random seed used to construct the graph embedding.
344352
:type seed: int, optional
345353
:param iterations: The number of iterations used to construct the graph embedding.
@@ -362,6 +370,17 @@ def update(self,
362370
:type cmap: str, optional
363371
"""
364372
_update_pos = False
373+
_update_col = False
374+
_update_layout = False
375+
if graph is not None:
376+
self.__graph = graph
377+
_update_pos = True
378+
_update_col = True
379+
_update_layout = True
380+
if dim is not None:
381+
self.__dim = dim
382+
_update_pos = True
383+
_update_layout = True
365384
if seed is not None:
366385
self.seed = seed
367386
_update_pos = True
@@ -370,7 +389,6 @@ def update(self,
370389
_update_pos = True
371390
if _update_pos:
372391
self._update_traces_pos()
373-
_update_col = False
374392
if agg is not None:
375393
self.agg = agg
376394
if (colors is not None) and (agg is not None):
@@ -391,7 +409,6 @@ def update(self,
391409
if title is not None:
392410
self.title = title
393411
self._update_traces_title()
394-
_update_layout = False
395412
if (width is not None) and (height is not None):
396413
self.width = width
397414
self.height = height

tests/test_plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def testTwoConnectedClusters(self):
2626
mp_plot2 = MapperLayoutInteractive(g, colors=data, dim=3)
2727
mp_plot2.plot()
2828
mp_plot2.update(
29+
graph=g,
30+
dim=2,
2931
colors=data,
3032
seed=123,
3133
iterations=10,

0 commit comments

Comments
 (0)