Skip to content

Commit

Permalink
fix: add exampels
Browse files Browse the repository at this point in the history
  • Loading branch information
maximelucas committed Oct 23, 2024
1 parent 1d2f279 commit d1fb3e0
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/GALLERY_HEADER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Gallery of examples
==================

Introductory examples to XGI.
2 changes: 2 additions & 0 deletions examples/advanced/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Advanced
--------
34 changes: 34 additions & 0 deletions examples/advanced/plot_colormaps_colorbars.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/advanced/plot_labels.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions examples/algorithms/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Algorithms
----------
19 changes: 19 additions & 0 deletions examples/algorithms/plot_simple_graph.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions examples/basic/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Basic
-----
19 changes: 19 additions & 0 deletions examples/basic/plot_simple_hypergraph.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/basic/plot_simple_hypergraph_hull.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/basic/plot_simple_hypergraph_multilayer.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/basic/plot_simple_hypergraph_outline.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/basic/plot_simple_simplicial_complex.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions examples/layouts/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Layouts
-------
19 changes: 19 additions & 0 deletions examples/layouts/plot_barycenter_spring_layout.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/layouts/plot_simple_graph.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions examples/layouts/plot_spiral_layout.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions examples/stats/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Stats
-----
28 changes: 28 additions & 0 deletions examples/stats/plot_color_stat.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d1fb3e0

Please sign in to comment.