Persistence Barcodes plotting #580
ismailguzel
started this conversation in
General
Replies: 1 comment
-
I was also looking for this, and think that it should be included, but they probably thought it is so trivial, that people can just plot directly from the resulting diagram. For anyone interested, here's a very naive implementation: import matplotlib.pyplot as plt
def plot_barcode(diag, dim, **kwargs):
"""
Plot the barcode for a persistence diagram using matplotlib
----------
diag: np.array: of shape (num_features, 3), i.e. each feature is
a triplet of (birth, death, dim) as returned by e.g.
VietorisRipsPersistence
dim: int: Dimension for which to plot
**kwargs
Returns
-------
None.
"""
diag_dim = diag[diag[:, 2] == dim]
birth = diag_dim[:, 0]; death = diag_dim[:, 1]
finite_bars = death[death != np.inf]
if len(finite_bars) > 0:
inf_end = 2 * max(finite_bars)
else:
inf_end = 2
death[death == np.inf] = inf_end
plt.figure(figsize=kwargs.get('figsize', (10, 5)))
for i, (b, d) in enumerate(zip(birth, death)):
if d == inf_end:
plt.plot([b, d], [i, i], color='k', lw=kwargs.get('linewidth', 2))
else:
plt.plot([b, d], [i, i], color=kwargs.get('color', 'b'), lw=kwargs.get('linewidth', 2))
plt.title(kwargs.get('title', 'Persistence Barcode'))
plt.xlabel(kwargs.get('xlabel', 'Filtration Value'))
plt.yticks([])
plt.tight_layout()
plt.show() Simply make infinite bars twice as long as the maximum death value, and color them black, otherwise just plot horizontal bars between b,d for each pair in the diagram. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Everyone,
Giotto-tda has persistent diagrams visualization functions
ploting_persistence.py
in plotting section. If I am not wrong, there is no barcodes plotting, isn't there ? I would like to try to contribute by writing persistence barcode plotting.It can added new parameter like
types
which can be either barcode or diagram for the functionplot_diagram()
. Maybe, one can write a new function plot_barcode like plot diagram.How can we start to be contibutor for giotto via writting plot barcodes. ?
Thank you for all
Beta Was this translation helpful? Give feedback.
All reactions