Plotly Data Visualization in Python
Updated: May 25, 2025

Plotly is an opensource python library designed to create data visualization in interactive way. Plotly library support over 40 types of charts from basic charts to advanced 3-d charts. Here are the types of charts it can support
Basic charts (Line, Bar, Scatter, etc)
Statistical charts
Scientific charts
Financial Charts
Maps(Choropleth, scatter geo, etc)
Bioinformatics
3D charts
Sub plots
Jupyter Widget Interaction
Custom Controls
Animations.
Installation:
To Install the plotly, use the following command
Pip install plotly
Plotly Modules
Plotly consist of two main modules. They are
1. chart_studio.plotly: It connects the local machine to the plotly cloud server. It contains functions that uploading and managing plots online.
2. Plotly.graph.objects: This module contains the object that are responsible for creating the plots.
Among all these types of charts, one of my favorite is the sunburst Chart. Let’s explore how to create it step by step.
A Sunburst Chart visualizes hierarchical data using a series of concentric rings, where each ring represents a different level in the hierarchy.
To create a sunburst chart, you will need a dataset that reflects the hierarchical relationships. This data set represents genders and distributes them by age and BMI on whether they are overweight or healthy.
import pandas as pd import plotly.express as px import plotly.io as pio pio.renderers.default = 'iframe' # Create the DataFrame data = { "Gender": ["Male", "Male", "Male", "Male", "Female", "Female", "Female", "Female"], "BMI": ["Normal", "Normal", "Overweight", "Overweight", "Normal", "Normal", "Overweight", "Overweight"], "AgeGroup": ["18–25", "26–35", "18–25", "26–35", "18–25", "26–35", "18–25", "26–35"], "Count": [120, 90, 60, 80, 90, 65, 30, 50] } df = pd.DataFrame(data) # Create Sunburst chart fig = px.sunburst(df, path=['Gender', 'BMI', 'AgeGroup'], values='Count', title="Health Distribution by Gender, BMI, and Age Group") |
Code Description:
df: The Data Frame containing the data.
path: A list of column names that defines the hierarchy in the sunburst chart. In the above example
First layer: Gender (Male or Female)
Second Layer: BMI Category (Normal or OverWeight)
Third Layer: Age Group (e.g18-25,26-35)
values: The column whose values determine the size of each segment. The count column has the number of individuals in each category.
This code will generate the Sunburst visualization as shown below
You can customize the SunBurst Chart using parameters like color, color_discreate_map and layout options for size and margin.
To summarize Sunburst Charts are useful for visualizing nested structures such as organizational charts, regional breakdowns, or category hierarchies. Plotly makes it intuitive and interactive with minimal code.
Next will create Funnel chart using plotly
Funnel charts are commonly used to visualize data across different stages of a business process. They play a key role in Business Intelligence by helping identify potential bottlenecks or areas of concern. For example, to observe the revenue or loss in a sales process for each stage, and displays values that are decreasing progressively. Each stage is illustrated as a percentage of the total of all values.
import plotly.express as px data = dict( number=[39, 27.4, 20.6, 11, 2], stage=["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"]) fig = px.funnel(data, x='number', y='stage') |
Code Description:
data: A dictionary (or DataFrame) containing the values for the funnel. In this case:
number represents the user counts
stage represents categorical stages like website Visit, Downloads, Potential customers, Requested Price, Invoice sent
x='number': Specifies the numerical column used to define the width of each funnel stage.
y='stage': Specifies the categorical column used to define the labels of each funnel level, shown vertically.
This code will generate the Funnel visualization as shown below

This funnel chart visually shows how users or leads drop off at each step in a process from visiting a website to receiving an invoice. It helps identify the category of where the revenue and loss occur.
To summarize, Plotly is a powerful tool to create interactive and visually appealing data visualizations. It supports wide range of charts from basic to advanced interactive charts like Sunburst and funnels charts. Now you have learned about the basics with Sunburst and funnel charts. Now you can explore more advanced Plotly features.


