Hierarchical and Flow Visualizations
Some data is organized in layers or moves between stages. Standard charts struggle to show this. This topic covers charts made for hierarchies, flows, and networks.
a. Treemaps and Sunburst Charts
A treemap shows a hierarchy as nested rectangles. The size of each rectangle shows a value, such as sales, and the nesting shows the groups, such as region, then country, then city. It makes good use of space and handles many categories.
A sunburst chart shows the same kind of hierarchy as rings. The center is the top level, and each ring outward is a deeper level.
fig = px.treemap(df, path=["region", "country", "city"], values="sales")
fig = px.sunburst(df, path=["region", "country", "city"], values="sales")Both are interactive in Plotly, so you can click a section to zoom in. They work best when the number of levels is small.
b. Sankey Diagrams
A Sankey diagram shows flows from one stage to another. The width of each band is proportional to the amount flowing. It is great for showing how users move through steps, or how money moves between categories.
import plotly.graph_objects as go
fig = go.Figure(go.Sankey(
node=dict(label=["Visits", "Signups", "Purchases", "Left"]),
link=dict(source=[0, 0, 1, 1], target=[1, 3, 2, 3],
value=[400, 600, 150, 250])
))
fig.show()The source and target lists use the index numbers of the nodes. Each position in the lists describes one flow.
Use Sankey diagrams when the path matters more than exact numbers. Keep the number of nodes small for a clear result.
c. Network Graphs
A network graph shows items as nodes and the links between them as edges. It suits data about relationships, such as social connections, web links, or supply chains.
import networkx as nx
G = nx.Graph()
G.add_edges_from([("A", "B"), ("A", "C"), ("B", "D"), ("C", "D")])
nx.draw(G, with_labels=True, node_color="skyblue")
plt.show()NetworkX builds and analyzes graphs, and it can draw them with Matplotlib. For interactive networks, you can use Plotly or a library such as PyVis.
Large networks turn into a hairball of lines. Filter to the most important nodes, size nodes by importance, and use a layout that spreads them out.
d. Choosing the Right Chart for Complex Relationships
Ask what the data structure is. If it has levels and parts of a whole, use a treemap or sunburst. If it has stages with amounts moving between them, use a Sankey diagram. If it has connections between entities, use a network graph.
Consider your audience. These charts look impressive, but they can be harder to read than simple bars. If a sorted bar chart tells the story, use it.
Always test with a first-time viewer. If they need a long explanation, the chart may be too complex. Clarity matters more than novelty.
Data Visualization Tutorial
Wesline Rinisha








