Created
February 14, 2023 17:03
-
-
Save muhammadanas0716/1a43cc3e33165fe3d05a3e6b2653b3b2 to your computer and use it in GitHub Desktop.
Population pyramid can be used to show either the distribution of the groups ordered by the volumne. Or it can also be used to show the stage-by-stage filtering of the population as it is used below to show how many people pass through each stage of a marketing funnel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import lbs | |
import numpy as np | |
import pandas as pd | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# Read data | |
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/email_campaign_funnel.csv") | |
# Draw Plot | |
plt.figure(figsize=(8, 5), dpi= 180) | |
group_col = 'Gender' | |
order_of_bars = df.Stage.unique()[::-1] | |
colors = [plt.cm.Spectral(i/float(len(df[group_col].unique())-1)) for i in range(len(df[group_col].unique()))] | |
for c, group in zip(colors, df[group_col].unique()): | |
sns.barplot(x='Users', y='Stage', data=df.loc[df[group_col]==group, :], order=order_of_bars, color=c, label=group) | |
# Decorations | |
plt.xlabel("$Users$") | |
plt.ylabel("Stage of Purchase") | |
plt.yticks(fontsize=12) | |
plt.title("Population Pyramid of the Marketing Funnel", fontsize=22) | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment