Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active March 25, 2022 08:33
Show Gist options
  • Select an option

  • Save izikeros/d73b2dce1df8f429f32e26e6ab92b341 to your computer and use it in GitHub Desktop.

Select an option

Save izikeros/d73b2dce1df8f429f32e26e6ab92b341 to your computer and use it in GitHub Desktop.
Function for visualization sample count on each step of filtering process

Plot filtering stages with funnel plot

Function for visualization sample count on each step of filtering process

Screenshot 2022-03-25 at 09 28 42

Requirements

Requires plotly_express installed.

Usage

Create "stages" dict during the filtering process. At each stage of filtering add elements both to lists under "count" and "stage" keys.

import plotly.express as px
# count - sample count after given stage
# stage - stage description
# Create "stages" dict during the filtering process. At each stage of filtering add elements both to lists under "count" and "stage" keys.
stages = {
"count": [90, 60, 50],
"stage": ["remove small numbers", "remove even numbers", "remove prime numbers"],
}
def plot_filtering_stages_funnel(
data, width=800, height=350, plot_title="Filtering stages"
):
fig = px.funnel(data, x="count", y="stage")
fig.update_layout(
width=width,
height=height,
title=plot_title,
)
# Make sure font is readable
fig["layout"]["font"] = dict(size=16)
fig.layout.template = "plotly_white"
fig.show()
plot_filtering_stages_funnel(stages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment