How to Create Funnel Charts in Python with Plotly

funnel-charts-plotly
Image by Author | ChatGPT

A funnel chart displays how data progresses through sequential stages, with each stage representing a subset of the previous stage. This visualization works well for showing conversion rates, process flow, and spotting bottlenecks in multi-step workflows like sales pipelines, website user journeys, or marketing campaigns.

Plotly brings dedicated funnel chart capabilities to Python that aren’t available in matplotlib and seaborn without custom coding. While other packages make you manually calculate proportions and build stacked bar charts as workarounds, Plotly provides built-in funnel chart functions with interactivity and clean styling. The charts export as HTML files that anyone can open in a web browser.

When to Use Funnel Charts

Funnel charts work best for visualizing sequential processes where each stage naturally filters the previous stage. They’re effective for:

  • Analyzing sales conversion rates through different pipeline stages
  • Tracking user behavior through website or app workflows
  • Measuring recruitment process efficiency from applications to hires
  • Visualizing manufacturing or quality control processes
  • Monitoring marketing campaign performance across touchpoints

Creating Your First Funnel Chart

Let’s create a funnel chart using a typical sales pipeline scenario. This example will show how prospects move through different stages from initial contact to closed deals.

 
import plotly.graph_objects as go

# Define the sales pipeline data
stages = ['Website Visitors', 'Leads Generated', 'Qualified Leads', 
          'Proposals Sent', 'Negotiations', 'Closed Deals']
values = [10000, 2500, 1200, 600, 300, 150]

# Create the funnel chart
fig = go.Figure(go.Funnel(
    y=stages,
    x=values,
    textinfo="value+percent initial"
))

# Save as HTML file
fig.write_html("sales_funnel.html")

This creates a basic funnel showing the progression from 10,000 website visitors down to 150 closed deals.

funnel charts plotly

Understanding the Output

The resulting visualization reveals several key insights about your sales process:

Conversion Bottlenecks: The width of each section shows the relative size of each stage. Sharp drops between stages indicate potential bottlenecks where you might improve conversion rates.

Overall Efficiency: The final conversion rate (1.5% in this example) appears both as text and visually through the funnel’s shape, making it easy to communicate overall process performance.

Stage-by-Stage Analysis: Each section displays both absolute numbers and percentages, allowing you to identify which specific transitions need the most attention.

Customizing Your Funnel Chart

You can enhance your funnel chart with colors, titles, and formatting:

 
import plotly.graph_objects as go

stages = ['Website Visitors', 'Leads Generated', 'Qualified Leads', 
          'Proposals Sent', 'Negotiations', 'Closed Deals']
values = [10000, 2500, 1200, 600, 300, 150]

fig = go.Figure(go.Funnel(
    y=stages,
    x=values,
    textinfo="value+percent initial",
    marker={"color": ["lightblue", "lightgreen", "yellow", 
                     "orange", "lightcoral", "red"]}
))

fig.update_layout(
    title="Sales Pipeline Conversion Analysis",
    font_size=12
)

fig.write_html("customized_funnel.html")

This enhanced version adds custom colors for each stage and includes a descriptive title to make the chart more presentation-ready.

funnel charts plotly

Analyzing Multiple Funnels

For comparative analysis, you can create multiple funnels side by side:

 
import plotly.graph_objects as go
from plotly.subplots import make_subplots

# Data for two different time periods
q1_values = [8000, 2000, 1000, 500, 250, 125]
q2_values = [10000, 2500, 1200, 600, 300, 150]
stages = ['Visitors', 'Leads', 'Qualified', 'Proposals', 'Negotiations', 'Closed']

# Create subplots
fig = make_subplots(
    rows=1, cols=2,
    specs=[[{"type": "funnel"}, {"type": "funnel"}]],
    subplot_titles=("Q1 2024", "Q2 2024")
)

fig.add_trace(go.Funnel(y=stages, x=q1_values), row=1, col=1)
fig.add_trace(go.Funnel(y=stages, x=q2_values), row=1, col=2)

fig.write_html("quarterly_comparison.html")

This comparison reveals that Q2 showed improvement across all stages, with particularly strong growth in initial visitor attraction and lead generation.

funnel charts plotly

Best Practices

Clear Stage Names: Use descriptive labels that clearly indicate what each stage represents. Avoid jargon or internal terminology that external viewers might not understand.

Logical Progression: Ensure your stages follow a natural sequence where each stage is genuinely a subset of the previous stage.

Meaningful Colors: Use color gradients or categorical colors that support your narrative. Red-to-green progressions work well for showing improvement or success.

Context Matters: Include time periods, data sources, and relevant benchmarks in your titles or annotations.

Common Patterns to Identify

When analyzing funnel charts, look for these patterns:

Steep Drops: Sharp decreases between consecutive stages suggest areas for process improvement or additional resource allocation.

Gradual Declines: Steady, proportional decreases often indicate healthy, well-optimized processes.

Bottlenecks: Stages with unusually high drop-off rates compared to adjacent stages deserve immediate attention.

Conversion Consistency: Stages with similar conversion rates suggest uniform process quality across those phases.

Alternative Approaches

If funnel charts don’t suit your needs, consider these alternatives:

  • Bar charts with conversion percentages for side-by-side stage comparison
  • Line plots showing trends over time for each funnel stage
  • Stacked bar charts when you need to show subcategories within each stage
  • Sankey diagrams for more complex multi-path processes

Conclusion

Funnel charts transform complex multi-stage processes into intuitive visual narratives. The sales pipeline example demonstrates how this technique can reveal bottlenecks and opportunities that might not be apparent from looking at spreadsheet data alone.

Effective funnel charts require meaningful stages, appropriate visual styling, and presenting the data in context that supports decision-making. When done well, these visualizations quickly communicate process performance and guide improvements across your organization.

Leave a Reply

Your email address will not be published. Required fields are marked *