Wheel Graph using Networkx Python (original) (raw)

Last Updated : 17 May, 2021

A wheel graph is a type of graph in which if we connect each node in an n-1 node cycle graph to nth node kept at the centre we get a wheel graph. The definition would be more clear after seeing the example below.

Wheel Graph with n nodes is represented by Wn .

Example:

W5:

W5

W6:

W6

Properties of Wheel Graph:

We will use the networkx module for realizing a Wheel graph. It comes with an inbuilt function networkx.wheel_graph() and can be illustrated using the networkx.draw() method. This module in Python is used for visualizing and analyzing different kinds of graphs.

Syntax:

networkx.wheel_graph(n)

Parameters:

networkx.draw(G, node_size, node_color)

Approach:

Implementation:

Python3 `

import required module

import networkx

number of nodes

n = 5

create object

G = networkx.wheel_graph(n)

illustrate graph

networkx.draw(G)

`

Output:

Explanation:

As we initialized n=5 the wheel graph with 5 nodes with a cycle graph having 4 nodes and a central node connected to all other nodes is printed using networkx inbuilt draw function.