5 Best Ways to Generate Funnel Plots Using Pygal in Python

Rate this post

πŸ’‘ Problem Formulation: You need to visualize a conversion funnel to track the stages of a process, typically in marketing or sales, that goes from initial awareness to ultimate conversion. Using Python and the pygal library, you require methods for generating funnel plots that effectively convey the reduction in data through each phase. For example, visualizing the steps from website visits to purchases.

Method 1: Basic Funnel Plot with Pygal

Pygal offers a straightforward way to create a funnel chart with a simple API. You can customize the colors, labels, and data points to match your project’s needs. The funnel chart in pygal is displayed in a vertical orientation by default, providing a quick visual representation of the progression through a process or pipeline.

Here’s an example:

import pygal

funnel_chart = pygal.Funnel()
funnel_chart.title = 'Conversion Funnel'
funnel_chart.add('Visits', 10000)
funnel_chart.add('Sign-ups', 5000)
funnel_chart.add('Purchases', 2500)

Output: This code snippet will generate a SVG file named basic_funnel.svg with a vertical funnel plot showing three stages: Visits, Sign-ups, and Purchases.

This basic funnel plot provides a clear visualization of each stage in the conversion process. By running the code, a chart is created with default settings that instantly provide insight into the data’s flow.

Method 2: Styled Funnel Plot

Customization is key when it comes to data visualization. Styling the funnel plot using Pygal’s built-in style module not only enhances the aesthetic appeal but also makes it easier to understand by emphasizing certain sections through the use of color and font adjustments.

Here’s an example:

from pygal.style import Style

custom_style = Style(colors=('#E80080','#404040','#9BC850'))
funnel_chart = pygal.Funnel(style=custom_style)
funnel_chart.title = 'Styled Funnel Chart'
funnel_chart.add('Visits', 10000)
funnel_chart.add('Sign-ups', 5000)
funnel_chart.add('Purchases', 2000)

Output: This code snippet will generate a SVG file named styled_funnel.svg with a funnel plot that is customized with specific colors for each stage.

Through this snippet, you can observe how simple alterations in styling can make a big difference in the visual output of the data, resulting in a more polished and themed chart.

Method 3: Adding Tooltips

Adding tooltips to a funnel plot is a convenient way to provide additional information to the user without cluttering the visual. When you hover over a section of the funnel plot, Pygal will display a tooltip containing data or text you’ve attached to each stage.

Here’s an example:

funnel_chart = pygal.Funnel(show_legend=False, tooltip_border_radius=10)
funnel_chart.title = 'Funnel Chart with Tooltips'
funnel_chart.add('Visits', [{'value': 10000, 'label': 'Total Visits'}])
funnel_chart.add('Sign-ups', [{'value': 5000, 'label': 'Total Sign-ups'}])
funnel_chart.add('Purchases', [{'value': 2500, 'label': 'Total Purchases'}])

Output: This code snippet will generate a SVG file named funnel_with_tooltips.svg with a funnel plot where each stage provides a tooltip with additional label information on hover.

This method enriches the interactivity of the funnel plot, giving an instant insight into the data points, which is particularly useful where the narrative behind the numbers is as significant as the figures themselves.

Method 4: Horizontal Funnel Plot

Sometimes a horizontal layout might be preferable for your funnel visualization. Pygal allows easy orientation changes, which can make comparisons and interpretation of data easier for certain audiences or specific project requirements.

Here’s an example:

horizontal_funnel = pygal.Funnel(horizontal=True)
horizontal_funnel.title = 'Horizontal Funnel Chart'
horizontal_funnel.add('Visits', 10000)
horizontal_funnel.add('Sign-ups', 5000)
horizontal_funnel.add('Purchases', 2500)

Output: This code snippet generates a SVG file named horizontal_funnel.svg where the funnel plot is oriented horizontally.

By changing the orientation of the funnel, this snippet demonstrates that Pygal can accommodate different stylistic choices while maintaining the integrity and clarity of the data being presented.

Bonus One-Liner Method 5: Quick Funnel Plot

If you’re in a hurry and just want to generate a funnel plot with minimum customization and code, Pygal’s one-liner approach is your best friend. You can set up and render a funnel plot inline.

Here’s an example:

pygal.Funnel().add('Steps', [10000, 5000, 2500]).render_to_file('quick_funnel.svg')

Output: Generates a SVG file named quick_funnel.svg representing the funnel plot with given data points.

This succinct example illustrates how Pygal enables rapid visualization. Despite its brevity, it produces a complete funnel plot, proving that effective visualization does not always require extensive coding.


  • Method 1: Basic Funnel Plot. Suitable for creating simple and clear funnel charts quickly. It lacks customization but is ideal for straightforward representations.
  • Method 2: Styled Funnel Plot. Allows for aesthetic customization which can make the funnel chart more engaging. However, more coding is required for the additional styles.
  • Method 3: Adding Tooltips. Incorporates interactive elements by adding tooltipsβ€”enhances the information relayed without overcrowding the visual. Can become cluttered with too much text.
  • Method 4: Horizontal Funnel Plot. Offers an alternative layout which may better suit certain projects or audiences. Flexibility in presentation style is a key benefit here.
  • Method 5: Quick Funnel Plot. Best for speed and efficiency in generating a funnel plot. Lacks detailed customization but is unbeatable for quick visualization needs.