.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_representations/plot_04_interchange.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_representations_plot_04_interchange.py: Interchange: HIF, HyperGodot files and other Python libraries ============================================================= hatvis reads and writes the Hypergraph Interchange Format (HIF), the text format of HyperGodot, SPMF itemsets, CSV and Excel incidence data, and converts to and from HyperNetX, XGI and Hypergraphx. A round trip through every format must give back the same hypergraph. .. GENERATED FROM PYTHON SOURCE LINES 12-42 .. code-block:: Python import pathlib import tempfile import matplotlib.pyplot as plt import hatvis as hv from hatvis import io H = hv.datasets.load_manufacturing_cps() tmp = pathlib.Path(tempfile.mkdtemp()) # [snippet:roundtrip] io.write_hif(H, tmp / "cps.hif.json") # shared by HyperNetX, XGI, Hypergraphx, HAT io.write_hypergodot(H, tmp / "cps.txt") # "W1 C1 SW #WEIGHT: 15 #GROUP: H" print((tmp / "cps.txt").read_text().splitlines()[0]) back = io.read_hif(tmp / "cps.hif.json") print("HIF round trip identical:", back == H) print("HyperGodot round trip, same hyperedges:", io.read_hypergodot(tmp / "cps.txt").edge_sets() == H.edge_sets()) # [/snippet:roundtrip] # [snippet:libraries] for lib in ("hypernetx", "xgi", "hypergraphx"): try: other = getattr(io, f"to_{lib}")(H) again = getattr(io, f"from_{lib}")(other) print(f"{lib:>11}: {type(other).__module__.split('.')[0]} object, " f"same sets = {sorted(map(sorted, again.edge_sets())) == sorted(map(sorted, H.edge_sets()))}") except ImportError: print(f"{lib:>11}: not installed") # [/snippet:libraries] .. rst-class:: sphx-glr-script-out .. code-block:: none W1 C1 SW #WEIGHT: 15 #GROUP: H HIF round trip identical: True HyperGodot round trip, same hyperedges: True hypernetx: hypernetx object, same sets = True xgi: xgi object, same sets = True hypergraphx: hypergraphx object, same sets = True .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(9, 3.2)) hv.plotting.plot_distributions(H, axes=axes) plt.tight_layout() .. image-sg:: /auto_examples/01_representations/images/sphx_glr_plot_04_interchange_001.png :alt: plot 04 interchange :srcset: /auto_examples/01_representations/images/sphx_glr_plot_04_interchange_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.575 seconds) .. _sphx_glr_download_auto_examples_01_representations_plot_04_interchange.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/01_representations/plot_04_interchange.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_interchange.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_interchange.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_interchange.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_