plotly

Plotly.Express.Funnel

“Funnel charts are types of plots used to represent the stages of the various business phenomenon. You will find them very common in business intelligence to gather and illustrate the potential problems at specific stages.
Each stage within a funnel plot is represented as a percentage of the overall total values.
In this article, we will explore how we can create various types of funnel plots using the Plotly express module.”

Plotly.express.funnel() Function Syntax

The syntax of the funnel() function is as shown:

plotly.express.funnel(data_frame=None, x=None, y=None, color=None, facet_row=None,

facet_col=None, facet_col_wrap=0, facet_row_spacing=None, facet_col_spacing=None,

hover_name=None, hover_data=None, custom_data=None, text=None,

animation_frame=None, animation_group=None, category_orders=None, labels=None,

color_discrete_sequence=None, color_discrete_map=None, opacity=None,

orientation=None, log_x=False, log_y=False, range_x=None, range_y=None, title=None,

template=None, width=None, height=None)

The following are the most important parameters you will need to understand when working with the funnel function.

  1. data_frame – this defines the data frame containing the column names used in the plot.
  2. x – sets the values used to position the marks along the x-axis in the cartesian plane.
  3. y – defines the values used to position the marks along the y axis of the cartesian coordinate.
  4. color – defines the values used to assign unique colors to the marks of the plot.
  5. opacity – sets the opacity for the markers. The values range between 0 and 1
  6. orientation – sets the orientation of the plot. “h” for horizontal orientation and “v” for vertical orientation.

Practical Example

Let us look at various code samples for creating funnel plots in Plotly express.

Let’s start by creating a simple funnel plot as shown in the code below:

import plotly.express as px
data = dict(
    compile_time = [23.45, 16.66, 14.22, 12.44, 8.11],
    stage = ['development', 'database integration', 'testing_deployment', 'refactor', 'production']
)
fig = px.funnel(data, x='compile_time', y='stage')
fig.show()

The code above creates a funnel illustrating the project compile time at various development stages.

The resulting figure is as shown:

To assign a unique color to each sector of the funnel based on the stage, we can use the color argument as:

import plotly.express as px
data = dict(
    compile_time = [23.45, 16.66, 14.22, 12.44, 8.11],
    stage = ['development', 'database integration', 'testing_deployment', 'refactor', 'production']
)
fig = px.funnel(data, x='compile_time', y='stage', color='stage')
fig.show()

Output:

To change the orientation, we can use the orientation argument as shown:

import plotly.express as px
data = dict(
    compile_time = [23.45, 16.66, 14.22, 12.44, 8.11],
    stage = ['development', 'database integration', 'testing_deployment', 'refactor', 'production']
)
fig = px.funnel(data, x='compile_time', y='stage', color='stage', orientation='v')
fig.show()

Output:

Termination

This article describes the basics of creating a funnel plot using the Plotly express module.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list