.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/advanced/plot_clustering.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_advanced_plot_clustering.py: ================= Communities ================= Compute and draw communities. .. GENERATED FROM PYTHON SOURCE LINES 8-28 .. image-sg:: /auto_examples/advanced/images/sphx_glr_plot_clustering_001.png :alt: plot clustering :srcset: /auto_examples/advanced/images/sphx_glr_plot_clustering_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import xgi # generate clustered hypergraph H1 = xgi.uniform_HPPM(100, 2, 3, 0.9, seed=0) H2 = xgi.uniform_HPPM(100, 3, 2, 0.9, seed=0) H = H1 << H2 H.cleanup() # compute communities with spectral clustering node_labels = xgi.spectral_clustering(H, k=2, max_iter=100, seed=0) H.set_node_attributes(node_labels, "group") # draw hypergraph pos = xgi.pca_transform(xgi.pairwise_spring_layout(H, seed=0)) xgi.draw(H, pos=pos, node_fc=H.nodes.attrs("group")) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.185 seconds) .. _sphx_glr_download_auto_examples_advanced_plot_clustering.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_clustering.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_clustering.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_clustering.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_