Returns the empty graph with n nodes and zero edges. 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 appear in the graph. create_using : Graph Instance
(n=0, create_using=None, default=nx.Graph, **kw)
| 205 | |
| 206 | @nodes_or_number(0) |
| 207 | def empty_graph(n=0, create_using=None, default=nx.Graph, **kw): |
| 208 | """Returns the empty graph with n nodes and zero edges. |
| 209 | |
| 210 | Parameters |
| 211 | ---------- |
| 212 | n : int or iterable container of nodes (default = 0) |
| 213 | If n is an integer, nodes are from `range(n)`. |
| 214 | If n is a container of nodes, those nodes appear in the graph. |
| 215 | create_using : Graph Instance, Constructor or None |
| 216 | Indicator of type of graph to return. |
| 217 | If a Graph-type instance, then clear and use it. |
| 218 | If None, use the `default` constructor. |
| 219 | If a constructor, call it to create an empty graph. |
| 220 | default : Graph constructor (optional, default = nx.Graph) |
| 221 | The constructor to use if create_using is None. |
| 222 | If None, then nx.Graph is used. |
| 223 | This is used when passing an unknown `create_using` value |
| 224 | through your home-grown function to `empty_graph` and |
| 225 | you want a default constructor other than nx.Graph. |
| 226 | |
| 227 | Examples |
| 228 | -------- |
| 229 | >>> G = nx.empty_graph(10) |
| 230 | >>> G.number_of_nodes() |
| 231 | 10 |
| 232 | >>> G.number_of_edges() |
| 233 | 0 |
| 234 | >>> G = nx.empty_graph("ABC") |
| 235 | >>> G.number_of_nodes() |
| 236 | 3 |
| 237 | >>> sorted(G) |
| 238 | ['A', 'B', 'C'] |
| 239 | |
| 240 | """ |
| 241 | if create_using is None: |
| 242 | G = default(**kw) |
| 243 | elif hasattr(create_using, "_adj"): |
| 244 | # create_using is a NetworkX style Graph |
| 245 | create_using.clear() |
| 246 | G = create_using |
| 247 | else: |
| 248 | # try create_using as constructor |
| 249 | G = create_using(**kw) |
| 250 | |
| 251 | n_name, nodes = n |
| 252 | G.add_nodes_from(nodes) |
| 253 | return G |
| 254 | |
| 255 | |
| 256 | @patch_docstring(nxa.ladder_graph) |
no test coverage detected