Funnel charts in Python using Plotly

Funnel Charts are often used to represent data in different stages of a business process. It’s an important mechanism in Business Intelligence to identify potential problem areas of a process. For example, it’s used to observe the revenue or loss in a sales process for each stage.

In this post, we’ll learn how to plot a funnel chart using a numerical dataset.

We are going to use a sample dataset from a dummy E-commerce firm’s social media campaign. The funnel chart will represent the flow of new users at different stages of the campaign.

These are the five stages of user flow:

  1. Link Visit : When a user clicks on the campaign link
  2. Sign-up : When a user creates an account
  3. Selection : When a user adds a product to the cart
  4. Purchase : When a user buys a product
  5. Review : When a user reviews a purchased product

Here is the table (dataset) containing values (number of users) for all the intermediate phases.

Phases Values
Visit 13873
Sign-up 10553
Selection 5443
Purchase 3703
Review 1708

Let’s represent the data in Python lists.

We will use Plotly shapes to draw the sections of a funnel. Each funnel section will be represented by a Quadrilateral (4 sided polygon).

A section will be a Rectangle if it has value equal to its next phase-value, or it’ll be a Isosceles Trapezoid (Isosceles Trapezium in British English) if its value is unequal to the next phase’s value.

We are using a fixed width for the plot and the section (phase) having the maximum users (value). All other sections will be drawn according to their values relative to the maximum value.

Each section will have a height of 100px and there will be a difference of 10px in successive sections.

To draw a section, we are going to use SVG paths.

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.

We can observe that the number of users is decreasing at each stage.

At the end of the funnel, we can see that 1,708 users have reviewed their purchase. The E-commerce firm can analyze their reviews and work on creating a better experience for them in future.

That’s an example use case of funnel charts, you can create them to monitor your business processes.