DEV Community

Dendi Handian
Dendi Handian

Posted on • Edited on

2

NetworkX built-in graph generators

Previously, I demonstrated how to load graph data from a json file and might be useful as a reference if you have any other graph data in JSON format. But if you want to play around with any kind of graphs without bothering yourself to put them first on a JSON file, you can use the networkx generators which contain graph that cover any case you need.

The documentation for the generator can be seen here. For a starter, you may want to use the graph Small category. These small graphs are useful if you want to understand a graph from a simple example as possible. So, let's try one of those:

import networkx as nx
import matplotlib.pyplot as plt

krackhardt_kite_graph = nx.generators.krackhardt_kite_graph()

nx.draw(krackhardt_kite_graph)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Even the Les Miserables graph from my previous post is there as well in Social Network category (I should have known this...)

import networkx as nx
import matplotlib.pyplot as plt

les_miserables_graph = nx.generators.les_miserables_graph()

nx.draw(les_miserables_graph)
plt.show()
Enter fullscreen mode Exit fullscreen mode

There are so many graphs in the generator and it's not possible for telling you about each graph in this post, so you may want to explore it yourself.


Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay