plotly

Plotly.Express.Funnel_area

“Funnel plots are a popular type of plot used to represent different stages of a specific aspect, especially in business intelligence.
A funnel area is very similar to a funnel plot, except each row in the provided data frame is visualized as a trapezoidal sector.
In this short tutorial, we will cover how you can create a funnel area using the Plotly express module.”

Let’s dive in.

Function Syntax

The function syntax is as shown below:

plotly.express.funnel_area(data_frame=None, names=None, values=None, color=None,

color_discrete_sequence=None, color_discrete_map=None, hover_name=None,

hover_data=None, custom_data=None, labels=None, title=None, template=None,

width=None, height=None, opacity=None)

Parameters:

  1. data_frame – specifies the data frame containing the columns used in the plot.
  2. names – sets the values used as labels for the funnel sectors.
  3. values – defines the values used to set the values associated with the funnel sectors.
  4. color – sets the values used to assign a unique color to the marks.
  5. color_discrete_sequence – defines a valid CSS color value used for the sector colors.
  6. title – sets the title for the figure.
  7. width\height – defines the width and height of the figure in pixels.
  8. opacity – defines the opacity for the funnel sectors. Opacity value must range between o and 1.

Example Illustration

The code below illustrates how to create a basic funnel area using the Plotly Express module.

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_area(data, values='compile_time', names='stage')
fig.show()

The code above should return a figure as shown:

You can change the color scheme by setting the color_discrete_sequence parameter as shown in the example 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_area(data, values='compile_time', names='stage', color_discrete_sequence=px.colors.sequential.Plasma_r)
fig.show()

This sets the color to Plasma_r as defined in plotly.express.colors.sequential.

The resulting output:

To set a dark background, we can use the template parameter as shown:

fig = px.funnel_area(data, values='compile_time', names='stage', color_discrete_sequence=px.colors.sequential.Plasma_r, template='plotly_dark')
fig.show()

The resulting figure is as shown:

To set figure title:

fig = px.funnel_area(data, values='compile_time', names='stage', color_discrete_sequence=px.colors.sequential.Plasma_r, template='plotly_dark', title='Funnel Area of Project Compile time')
fig.show()

The code above should add the text in the title parameter as the title.

Example output:

And that’s it for this one.

Closing

This article illustrates the fundamentals of creating funnel area plots 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