Segmented Funnel charts in Python using Plotly

Funnel Charts are often used to represent data in different stages of a business process. You can learn more about them in our previous post, Funnel charts in Python using Plotly.

In this post, we will learn about creating Segmented Funnel Charts.

Instead of having a single source of data like the funnel charts, the segmented funnel charts have multiple data sources.

We are going to use a sample dataset from a dummy E-commerce firm’s quarterly product sales. The funnel chart will represent the users at different stages of the process. We can also inspect the number of users contributed by different segments (channels).

Here is the dataset for this post, segment-funnel-dataset.csv.

IPython Notebook for the source code is available here.

Ad Media Affiliates Referrals Direct
Visit 9806 13105 6505 2517 24321
Sign-up 3065 6096 3011 1710 11453
Selection 1765 3592 2234 1555 8603
Purchase 1507 2403 1610 1005 5798

We can calculate the total number of users in each phase using DataFrame.iterrows() method.

Number of phases and segments can be calculated using the shape (returns a tuple) attribute of DataFrame.

We are using a fixed width for the plot and the width of each phase will be calculated according to the total users compared to the initial phase.

A phase in the chart will be a rectangle made of smaller rectangles representing different segments.

We will use text mode to draw the name of phase and its value.

We will style the plot by changing the background color of the plot and the plot paper, hiding the legend and tick labels, and removing the zeroline.

You can even analyze different segments by hovering on them.