Repository: networkx/networkx

Issue:
Improving Triads Algorithms Documentation
<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->
There are 7 Functions under Triads.

1. [triadic_census](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.triadic_census.html#networkx.algorithms.triads.triadic_census)(G[, nodelist])
2. [random_triad](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.random_triad.html#networkx.algorithms.triads.random_triad)(G)
3. [triads_by_type](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.triads_by_type.html#networkx.algorithms.triads.triads_by_type)(G)
4. [triad_type](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.triad_type.html#networkx.algorithms.triads.triad_type)(G)
5. [is_triad](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.is_triad.html#networkx.algorithms.triads.is_triad)(G)
6. [all_triads](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.all_triads.html#networkx.algorithms.triads.all_triads)(G)
7. [all_triplets](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.triads.all_triplets.html#networkx.algorithms.triads.all_triplets)(G) 

None of these have any examples included. I will like to include some and also improve the documentation on Triads and its Types. 

NetworkX version: 2.6.2


Discussion:
Thanks for the report @0ddoes! Feel free to work on them.

Resolving patch:
diff --git a/networkx/algorithms/triads.py b/networkx/algorithms/triads.py
--- a/networkx/algorithms/triads.py
+++ b/networkx/algorithms/triads.py
@@ -149,6 +149,30 @@ def triadic_census(G, nodelist=None):
     census : dict
        Dictionary with triad type as keys and number of occurrences as values.
 
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1), (3, 4), (4, 1), (4, 2)])
+    >>> triadic_census = nx.triadic_census(G)
+    >>> for key, value in triadic_census.items():
+    ...     print(f"{key}: {value}")
+    ...
+    003: 0
+    012: 0
+    102: 0
+    021D: 0
+    021U: 0
+    021C: 0
+    111D: 0
+    111U: 0
+    030T: 2
+    030C: 2
+    201: 0
+    120D: 0
+    120U: 0
+    120C: 0
+    210: 0
+    300: 0
+
     Notes
     -----
     This algorithm has complexity $O(m)$ where $m$ is the number of edges in
@@ -224,6 +248,15 @@ def is_triad(G):
     -------
     istriad : boolean
        Whether G is a valid triad
+
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
+    >>> nx.is_triad(G)
+    True
+    >>> G.add_edge(0, 1)
+    >>> nx.is_triad(G)
+    False
     """
     if isinstance(G, nx.Graph):
         if G.order() == 3 and nx.is_directed(G):
@@ -245,6 +278,13 @@ def all_triplets(G):
     -------
     triplets : generator of 3-tuples
        Generator of tuples of 3 nodes
+
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 4)])
+    >>> list(nx.all_triplets(G))
+    [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
+
     """
     triplets = combinations(G.nodes(), 3)
     return triplets
@@ -263,6 +303,17 @@ def all_triads(G):
     -------
     all_triads : generator of DiGraphs
        Generator of triads (order-3 DiGraphs)
+
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1), (3, 4), (4, 1), (4, 2)])
+    >>> for triad in nx.all_triads(G):
+    ...     print(triad.edges)
+    [(1, 2), (2, 3), (3, 1)]
+    [(1, 2), (4, 1), (4, 2)]
+    [(3, 1), (3, 4), (4, 1)]
+    [(2, 3), (3, 4), (4, 2)]
+
     """
     triplets = combinations(G.nodes(), 3)
     for triplet in triplets:
@@ -272,6 +323,29 @@ def all_triads(G):
 @not_implemented_for("undirected")
 def triads_by_type(G):
     """Returns a list of all triads for each triad type in a directed graph.
+    There are exactly 16 different types of triads possible. Suppose 1, 2, 3 are three
+    nodes, they will be classified as a particular triad type if their connections
+    are as follows:
+
+    - 003: 1, 2, 3
+    - 012: 1 -> 2, 3
+    - 102: 1 <-> 2, 3
+    - 021D: 1 <- 2 -> 3
+    - 021U: 1 -> 2 <- 3
+    - 021C: 1 -> 2 -> 3
+    - 111D: 1 <-> 2 <- 3
+    - 111U: 1 <-> 2 -> 3
+    - 030T: 1 -> 2 -> 3, 1 -> 3
+    - 030C: 1 <- 2 <- 3, 1 -> 3
+    - 201: 1 <-> 2 <-> 3
+    - 120D: 1 <- 2 -> 3, 1 <-> 3
+    - 120U: 1 -> 2 <- 3, 1 <-> 3
+    - 120C: 1 -> 2 -> 3, 1 <-> 3
+    - 210: 1 -> 2 <-> 3, 1 <-> 3
+    - 300: 1 <-> 2 <-> 3, 1 <-> 3
+
+    Refer to the :doc:`example gallery <auto_examples/graph/plot_triad_types>`
+    for visual examples of the triad types.
 
     Parameters
     ----------
@@ -282,6 +356,21 @@ def triads_by_type(G):
     -------
     tri_by_type : dict
        Dictionary with triad types as keys and lists of triads as values.
+
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 1), (5, 6), (5, 4), (6, 7)])
+    >>> dict = nx.triads_by_type(G)
+    >>> dict['120C'][0].edges()
+    OutEdgeView([(1, 2), (1, 3), (2, 3), (3, 1)])
+    >>> dict['012'][0].edges()
+    OutEdgeView([(1, 2)])
+
+    References
+    ----------
+    .. [1] Snijders, T. (2012). "Transitivity and triads." University of
+        Oxford.
+        https://web.archive.org/web/20170830032057/http://www.stats.ox.ac.uk/~snijders/Trans_Triads_ha.pdf
     """
     # num_triads = o * (o - 1) * (o - 2) // 6
     # if num_triads > TRIAD_LIMIT: print(WARNING)
@@ -307,6 +396,15 @@ def triad_type(G):
     triad_type : str
        A string identifying the triad type
 
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
+    >>> nx.triad_type(G)
+    '030C'
+    >>> G.add_edge(1, 3)
+    >>> nx.triad_type(G)
+    '120C'
+
     Notes
     -----
     There can be 6 unique edges in a triad (order-3 DiGraph) (so 2^^6=64 unique
@@ -394,6 +492,14 @@ def random_triad(G):
     -------
     G2 : subgraph
        A randomly selected triad (order-3 NetworkX DiGraph)
+
+    Examples
+    --------
+    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 1), (5, 6), (5, 4), (6, 7)])
+    >>> triad = nx.random_triad(G)
+    >>> triad.edges
+    OutEdgeView([(1, 3), (3, 1)])
+
     """
     nodes = sample(list(G.nodes()), 3)
     G2 = G.subgraph(nodes)


Test patch: