.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_representations/plot_01_quickstart.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_01_quickstart.py: A first hypergraph: incidence matrix, dual and degrees ====================================================== A hypergraph :math:`H=(V,E)` consists of vertices and hyperedges, where every hyperedge is an arbitrary subset of the vertices. This script builds the five-vertex example of the HAT-VIS paper, prints its incidence matrix :math:`\mathbf{B}`, the dual hypergraph :math:`H^*` (incidence :math:`\mathbf{B}^\mathsf{T}`) and the basic statistics, and draws the two views side by side. .. GENERATED FROM PYTHON SOURCE LINES 14-28 .. code-block:: Python import matplotlib.pyplot as plt import hatvis as hv from hatvis.plotting import draw_hypergraph, plot_incidence # [snippet:build] H = hv.Hypergraph({"e1": ["v1", "v2", "v3"], "e2": ["v1", "v2", "v4"], "e3": ["v3", "v4", "v5"]}) print(H.to_dataframe().astype(int)) print(H.degrees().to_dict(), H.edge_sizes().to_dict()) D = H.dual() print(D.edge_dict()) # [/snippet:build] print(H.summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none e1 e2 e3 v1 1 1 0 v2 1 1 0 v3 1 0 1 v4 0 1 1 v5 0 0 1 {'v1': 2, 'v2': 2, 'v3': 2, 'v4': 2, 'v5': 1} {'e1': 3, 'e2': 3, 'e3': 3} {'v1': ('e1', 'e2'), 'v2': ('e1', 'e2'), 'v3': ('e1', 'e3'), 'v4': ('e2', 'e3'), 'v5': ('e3',)} vertices 5.0 hyperedges 3.0 incidences 9.0 density 0.6 mean size 3.0 max size 3.0 mean degree 1.8 max degree 2.0 isolated vertices 0.0 duplicate hyperedges 0.0 Name: hypergraph, dtype: float64 .. GENERATED FROM PYTHON SOURCE LINES 29-33 The incidence matrix (left) is a complete description; the node-link view (middle) draws every hyperedge as a padded convex hull around its members, here with the force-directed layout of HyperGodot; the dual (right) swaps the roles: the hyperedges become the vertices. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(13, 3.8), gridspec_kw={"width_ratios": [1, 1.3, 1.3]}) plot_incidence(H, order=None, ax=axes[0], title="incidence matrix") draw_hypergraph(H, layout="force", ax=axes[1], title="H", legend=False, edge_labels=True, style="smooth") draw_hypergraph(D, layout="force", ax=axes[2], title="dual H*", legend=False, edge_labels=True, style="smooth") plt.tight_layout() .. image-sg:: /auto_examples/01_representations/images/sphx_glr_plot_01_quickstart_001.png :alt: incidence matrix, H, dual H* :srcset: /auto_examples/01_representations/images/sphx_glr_plot_01_quickstart_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.398 seconds) .. _sphx_glr_download_auto_examples_01_representations_plot_01_quickstart.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_01_quickstart.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_quickstart.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_quickstart.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_quickstart.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_