Returns the empty graph with n nodes and zero edges. .. plot:: >>> nx.draw(nx.empty_graph(5)) Parameters ---------- n : int or iterable container of nodes (default = 0) If n is an integer, nodes are from `range(n)`. If n is a container of nodes, those nodes
(n=0, create_using=None, default=Graph)
| 564 | @nx._dispatchable(graphs=None, returns_graph=True) |
| 565 | @nodes_or_number(0) |
| 566 | def empty_graph(n=0, create_using=None, default=Graph): |
| 567 | """Returns the empty graph with n nodes and zero edges. |
| 568 | |
| 569 | .. plot:: |
| 570 | |
| 571 | >>> nx.draw(nx.empty_graph(5)) |
| 572 | |
| 573 | Parameters |
| 574 | ---------- |
| 575 | n : int or iterable container of nodes (default = 0) |
| 576 | If n is an integer, nodes are from `range(n)`. |
| 577 | If n is a container of nodes, those nodes appear in the graph. |
| 578 | create_using : Graph Instance, Constructor or None |
| 579 | Indicator of type of graph to return. |
| 580 | If a Graph-type instance, then clear and use it. |
| 581 | If None, use the `default` constructor. |
| 582 | If a constructor, call it to create an empty graph. |
| 583 | default : Graph constructor (optional, default = nx.Graph) |
| 584 | The constructor to use if create_using is None. |
| 585 | If None, then nx.Graph is used. |
| 586 | This is used when passing an unknown `create_using` value |
| 587 | through your home-grown function to `empty_graph` and |
| 588 | you want a default constructor other than nx.Graph. |
| 589 | |
| 590 | Examples |
| 591 | -------- |
| 592 | >>> G = nx.empty_graph(10) |
| 593 | >>> G.number_of_nodes() |
| 594 | 10 |
| 595 | >>> G.number_of_edges() |
| 596 | 0 |
| 597 | >>> G = nx.empty_graph("ABC") |
| 598 | >>> G.number_of_nodes() |
| 599 | 3 |
| 600 | >>> sorted(G) |
| 601 | ['A', 'B', 'C'] |
| 602 | |
| 603 | Notes |
| 604 | ----- |
| 605 | The variable create_using should be a Graph Constructor or a |
| 606 | "graph"-like object. Constructors, e.g. `nx.Graph` or `nx.MultiGraph` |
| 607 | will be used to create the returned graph. "graph"-like objects |
| 608 | will be cleared (nodes and edges will be removed) and refitted as |
| 609 | an empty "graph" with nodes specified in n. This capability |
| 610 | is useful for specifying the class-nature of the resulting empty |
| 611 | "graph" (i.e. Graph, DiGraph, MyWeirdGraphClass, etc.). |
| 612 | |
| 613 | The variable create_using has three main uses: |
| 614 | Firstly, the variable create_using can be used to create an |
| 615 | empty digraph, multigraph, etc. For example, |
| 616 | |
| 617 | >>> n = 10 |
| 618 | >>> G = nx.empty_graph(n, create_using=nx.DiGraph) |
| 619 | |
| 620 | will create an empty digraph on n nodes. |
| 621 | |
| 622 | Secondly, one can pass an existing graph (digraph, multigraph, |
| 623 | etc.) via create_using. For example, if G is an existing graph |
searching dependent graphs…