From d1fb3e028b3976b4d29c2e31ba0101321875adc4 Mon Sep 17 00:00:00 2001 From: Maxime Lucas Date: Wed, 23 Oct 2024 17:36:04 +0200 Subject: [PATCH] fix: add exampels --- examples/GALLERY_HEADER.txt | 4 +++ examples/advanced/README.txt | 2 ++ examples/advanced/plot_colormaps_colorbars.py | 34 +++++++++++++++++++ examples/advanced/plot_labels.py | 19 +++++++++++ examples/algorithms/README.txt | 2 ++ examples/algorithms/plot_simple_graph.py | 19 +++++++++++ examples/basic/README.txt | 2 ++ examples/basic/plot_simple_hypergraph.py | 19 +++++++++++ examples/basic/plot_simple_hypergraph_hull.py | 19 +++++++++++ .../plot_simple_hypergraph_multilayer.py | 19 +++++++++++ .../basic/plot_simple_hypergraph_outline.py | 19 +++++++++++ .../basic/plot_simple_simplicial_complex.py | 19 +++++++++++ examples/layouts/README.txt | 2 ++ .../layouts/plot_barycenter_spring_layout.py | 19 +++++++++++ examples/layouts/plot_simple_graph.py | 19 +++++++++++ examples/layouts/plot_spiral_layout.py | 19 +++++++++++ examples/stats/README.txt | 2 ++ examples/stats/plot_color_stat.py | 28 +++++++++++++++ 18 files changed, 266 insertions(+) create mode 100644 examples/GALLERY_HEADER.txt create mode 100644 examples/advanced/README.txt create mode 100644 examples/advanced/plot_colormaps_colorbars.py create mode 100644 examples/advanced/plot_labels.py create mode 100644 examples/algorithms/README.txt create mode 100644 examples/algorithms/plot_simple_graph.py create mode 100644 examples/basic/README.txt create mode 100644 examples/basic/plot_simple_hypergraph.py create mode 100644 examples/basic/plot_simple_hypergraph_hull.py create mode 100644 examples/basic/plot_simple_hypergraph_multilayer.py create mode 100644 examples/basic/plot_simple_hypergraph_outline.py create mode 100644 examples/basic/plot_simple_simplicial_complex.py create mode 100644 examples/layouts/README.txt create mode 100644 examples/layouts/plot_barycenter_spring_layout.py create mode 100644 examples/layouts/plot_simple_graph.py create mode 100644 examples/layouts/plot_spiral_layout.py create mode 100644 examples/stats/README.txt create mode 100644 examples/stats/plot_color_stat.py diff --git a/examples/GALLERY_HEADER.txt b/examples/GALLERY_HEADER.txt new file mode 100644 index 00000000..758a9489 --- /dev/null +++ b/examples/GALLERY_HEADER.txt @@ -0,0 +1,4 @@ +Gallery of examples +================== + +Introductory examples to XGI. \ No newline at end of file diff --git a/examples/advanced/README.txt b/examples/advanced/README.txt new file mode 100644 index 00000000..a378715c --- /dev/null +++ b/examples/advanced/README.txt @@ -0,0 +1,2 @@ +Advanced +-------- \ No newline at end of file diff --git a/examples/advanced/plot_colormaps_colorbars.py b/examples/advanced/plot_colormaps_colorbars.py new file mode 100644 index 00000000..6b70eaf5 --- /dev/null +++ b/examples/advanced/plot_colormaps_colorbars.py @@ -0,0 +1,34 @@ +""" +======================== +Colormaps and colorbars +======================== + +Set colormaps and show colorbars. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) + +fig, ax = plt.subplots(figsize=(6, 2.5)) + +ax, collections = xgi.draw( + H, + pos=pos, + node_fc=H.nodes.degree, + edge_fc=H.edges.size, + edge_fc_cmap="viridis", + node_fc_cmap="mako_r", +) + +node_col, _, edge_col = collections + +plt.colorbar(node_col, label="Node degree") +plt.colorbar(edge_col, label="Edge size") + +plt.show() \ No newline at end of file diff --git a/examples/advanced/plot_labels.py b/examples/advanced/plot_labels.py new file mode 100644 index 00000000..0b3f691b --- /dev/null +++ b/examples/advanced/plot_labels.py @@ -0,0 +1,19 @@ +""" +================= +Show labels +================= + +Draw hypergraph with labels. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos, node_labels=True, node_size=15, hyperedge_labels=True) + +plt.show() \ No newline at end of file diff --git a/examples/algorithms/README.txt b/examples/algorithms/README.txt new file mode 100644 index 00000000..8a2ee75b --- /dev/null +++ b/examples/algorithms/README.txt @@ -0,0 +1,2 @@ +Algorithms +---------- \ No newline at end of file diff --git a/examples/algorithms/plot_simple_graph.py b/examples/algorithms/plot_simple_graph.py new file mode 100644 index 00000000..195b399f --- /dev/null +++ b/examples/algorithms/plot_simple_graph.py @@ -0,0 +1,19 @@ +""" +================= +Simple hypergraph +================= + +Draw simple hypergraph with manual layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4], [4, 5, 6, 7]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos) + +plt.show() \ No newline at end of file diff --git a/examples/basic/README.txt b/examples/basic/README.txt new file mode 100644 index 00000000..1daa5c85 --- /dev/null +++ b/examples/basic/README.txt @@ -0,0 +1,2 @@ +Basic +----- \ No newline at end of file diff --git a/examples/basic/plot_simple_hypergraph.py b/examples/basic/plot_simple_hypergraph.py new file mode 100644 index 00000000..70e533db --- /dev/null +++ b/examples/basic/plot_simple_hypergraph.py @@ -0,0 +1,19 @@ +""" +================= +Simple hypergraph +================= + +Draw simple hypergraph with manual layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos) + +plt.show() \ No newline at end of file diff --git a/examples/basic/plot_simple_hypergraph_hull.py b/examples/basic/plot_simple_hypergraph_hull.py new file mode 100644 index 00000000..38a1104f --- /dev/null +++ b/examples/basic/plot_simple_hypergraph_hull.py @@ -0,0 +1,19 @@ +""" +=================================== +Simple hypergraph with convex hulls +=================================== + +Draw simple hypergraph with convex hulls and manual layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos, hull=True) + +plt.show() \ No newline at end of file diff --git a/examples/basic/plot_simple_hypergraph_multilayer.py b/examples/basic/plot_simple_hypergraph_multilayer.py new file mode 100644 index 00000000..6dc7fe9e --- /dev/null +++ b/examples/basic/plot_simple_hypergraph_multilayer.py @@ -0,0 +1,19 @@ +""" +=================================== +Simple hypergraph as multilayer +=================================== + +Draw simple hypergraph as multilayer +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +ax3 = plt.axes(projection="3d") # requires a 3d axis +xgi.draw_multilayer(H, ax=ax3) + +plt.show() \ No newline at end of file diff --git a/examples/basic/plot_simple_hypergraph_outline.py b/examples/basic/plot_simple_hypergraph_outline.py new file mode 100644 index 00000000..b5cc3a0f --- /dev/null +++ b/examples/basic/plot_simple_hypergraph_outline.py @@ -0,0 +1,19 @@ +""" +=================================== +Simple hypergraph with outline +=================================== + +Draw simple hypergraph with outline and manual layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos, hull=True, edge_fc="white") + +plt.show() \ No newline at end of file diff --git a/examples/basic/plot_simple_simplicial_complex.py b/examples/basic/plot_simple_simplicial_complex.py new file mode 100644 index 00000000..4658b719 --- /dev/null +++ b/examples/basic/plot_simple_simplicial_complex.py @@ -0,0 +1,19 @@ +""" +========================= +Simple simplicial complex +========================= + +Draw simple simplicial complex with manual layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.SimplicialComplex(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos) + +plt.show() \ No newline at end of file diff --git a/examples/layouts/README.txt b/examples/layouts/README.txt new file mode 100644 index 00000000..0c7f36d1 --- /dev/null +++ b/examples/layouts/README.txt @@ -0,0 +1,2 @@ +Layouts +------- \ No newline at end of file diff --git a/examples/layouts/plot_barycenter_spring_layout.py b/examples/layouts/plot_barycenter_spring_layout.py new file mode 100644 index 00000000..b765cd02 --- /dev/null +++ b/examples/layouts/plot_barycenter_spring_layout.py @@ -0,0 +1,19 @@ +""" +================= +Barycenter spring +================= + +Draw simple hypergraph with barycenter_spring layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.barycenter_spring_layout(H, seed=1) +xgi.draw(H, pos=pos) + +plt.show() diff --git a/examples/layouts/plot_simple_graph.py b/examples/layouts/plot_simple_graph.py new file mode 100644 index 00000000..0cdfff75 --- /dev/null +++ b/examples/layouts/plot_simple_graph.py @@ -0,0 +1,19 @@ +""" +================= +Circular +================= + +Draw simple hypergraph with circular layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.circular_layout(H) +xgi.draw(H, pos=pos) + +plt.show() \ No newline at end of file diff --git a/examples/layouts/plot_spiral_layout.py b/examples/layouts/plot_spiral_layout.py new file mode 100644 index 00000000..4e3bdd76 --- /dev/null +++ b/examples/layouts/plot_spiral_layout.py @@ -0,0 +1,19 @@ +""" +================= +Spiral +================= + +Draw simple hypergraph with spiral layout. +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + + +pos = xgi.spiral_layout(H) +xgi.draw(H, pos=pos) + +plt.show() \ No newline at end of file diff --git a/examples/stats/README.txt b/examples/stats/README.txt new file mode 100644 index 00000000..1f3a2853 --- /dev/null +++ b/examples/stats/README.txt @@ -0,0 +1,2 @@ +Stats +----- \ No newline at end of file diff --git a/examples/stats/plot_color_stat.py b/examples/stats/plot_color_stat.py new file mode 100644 index 00000000..1fe33584 --- /dev/null +++ b/examples/stats/plot_color_stat.py @@ -0,0 +1,28 @@ +""" +=================== +Color based on stat +=================== + +Set node colors based on stat +""" + +import matplotlib.pyplot as plt +import xgi + +hyperedges = [[1, 2, 3], [3, 4, 5], [3, 6], [6, 7, 8, 9], [1, 4, 10, 11, 12], [1, 4]] +H = xgi.Hypergraph(hyperedges) + +pos = xgi.barycenter_spring_layout(H, seed=1) + +ax, collections = xgi.draw( + H, + pos=pos, + node_fc=H.nodes.degree, + edge_fc="grey", + node_fc_cmap="mako_r", +) + +node_col, _, edge_col = collections + +plt.colorbar(node_col, label="Node degree") +plt.show() \ No newline at end of file