giotto-ai / giotto-tda

A high-performance topological machine learning toolbox in Python
https://giotto-ai.github.io/gtda-docs
Other
845 stars 173 forks source link

No visualization after plot_diagram #691

Open ghoshanirban opened 6 months ago

ghoshanirban commented 6 months ago

I am fiddling with the code provided at https://giotto-ai.github.io/gtda-docs/latest/notebooks/vietoris_rips_quickstart.html The code runs fine, but I am not getting visualization output after

from gtda.plotting import plot_diagram

i = 0
plot_diagram(diagrams[i])

I have tried PyCharm and the terminal on Ubuntu 22.04. Is anyone else facing the same issue?

beew commented 6 months ago

Hi, I ran into the same issue when I ran the code in spyder (also Ubuntu 22.04). Turns out it works in Jupyter notebook. Looks like somehow the plotting method is written for notebook.

https://github.com/giotto-ai/giotto-tda/issues/661

VascoSch92 commented 6 months ago

Looking at the code: the method is giving back a fig but it is not displaying it (this is what happens automatically on a notebook)

Try with

plot_diagram(diagrams[i]).show()

Or

print(plot_diagram(diagrams[i]))
ghoshanirban commented 6 months ago

Looking at the code: the method is giving back a fig but it is not displaying it (this is what happens automatically on a notebook)

Try with

plot_diagram(diagrams[i]).show()

Or

print(plot_diagram(diagrams[i]))

Thank you; show() worked with PyCharm and the plot got opened in a browser window. Matplotlib support would have been great. Any ideas on how to use it in this case?

VascoSch92 commented 6 months ago

The method name is really bad because it is not plotting but returning a plot, and then you have to plot it. I will suggest to rename that as get_diagram, generate_diagram, ....

Matplotlib support would have been great. Any ideas on how to use it in this case?

What do you mean? Can you give some more details or an user-case? :-)

ghoshanirban commented 6 months ago

I wondered if the plot can be exported to a pdf generated using Matplotlib.

VascoSch92 commented 6 months ago

Give a look here. :-)

And here there is the documentation on matplotlib.

ghoshanirban commented 6 months ago

Thanks! I was expecting gudhi-like support:

gudhi.plot_persistence_barcode(barcodes) plt.savefig("persistence-barcode.pdf", format="pdf", bbox_inches="tight")

Do we have this kind of support for giotto-tda?

matteocao commented 4 months ago

@ghoshanirban we do not currently have the feature you mention: we would gladly accept a PR from you adding this if you are interested however!