giotto-ai / tutorial_mapper

Other
13 stars 7 forks source link

Adapt the tutorial to the new mapper API #8

Closed wreise closed 4 years ago

wreise commented 4 years ago

gtda.mappers.visualization:plot_static_mapper_graph has less flexibility regarding colors and the colormaps. Hence, the colors are updated directly on the figure.

WeilerP commented 4 years ago

There are a few flake8 linting violations in the notebook. For consistency, these could (or should?) be resolved. For example:

plotly_kwargs = {'node_trace_marker_colorscale': None,
                'node_trace_marker_showscale': False
                }

instead of

plotly_kwargs = {'node_trace_marker_colorscale': None,
                 'node_trace_marker_showscale': False}
WeilerP commented 4 years ago

If I am not mistaken, the following code is reused in almost all cells:

# get cluster member indices
node_elements = graph["node_metadata"]["node_elements"]
# configure choice of layout (x,z values)
layout = np.array([np.mean(coords[el], axis=0)[[0, 2]] for el in node_elements])
# define node coloring
node_colors = np.array([data.loc[el, "color"].value_counts().index[0] for el in node_elements])
plotly_kwargs = {'node_trace_marker_colorscale': None,
                'node_trace_marker_showscale': False
                }

# initialise and display figure
fig = plot_static_mapper_graph(pipeline, coords,
                               layout, plotly_kwargs=plotly_kwargs)
fig.update_traces(patch={'hoverlabel_bgcolor': node_colors,
                   'marker_color': node_colors})
fig.show(config={'scrollZoom':True})

For readability, I think this part should be defined either once as a function in the notebook or in a separate utils.py file.