final changes for spider charts
This commit is contained in:
parent
b9a3d05a2f
commit
52b39e03be
File diff suppressed because one or more lines are too long
|
@ -140,22 +140,27 @@ def radar_mp_plot(df, categories, index) :
|
||||||
def radar_mp_plot_all(df, type_of_activity) :
|
def radar_mp_plot_all(df, type_of_activity) :
|
||||||
|
|
||||||
# table summarizing variables relative to marketing personae
|
# table summarizing variables relative to marketing personae
|
||||||
df_mp = df.groupby("segment")[["gender_female", "gender_male", "gender_other", "country_fr"]].mean().reset_index()
|
df_mp = df.groupby("segment")[["gender_female", "gender_male", "gender_other", "age"]].mean().reset_index()
|
||||||
df_mp.insert(3, "share_known_gender", df_mp["gender_female"]+df_mp["gender_male"])
|
#df_mp.insert(3, "share_known_gender", df_mp["gender_female"]+df_mp["gender_male"])
|
||||||
df_mp.insert(4, "share_of_women", df_mp["gender_female"]/(df_mp["share_known_gender"]))
|
df_mp.insert(4, "share_of_women", df_mp["gender_female"]/(df_mp["gender_female"]+df_mp["gender_male"]))
|
||||||
|
|
||||||
# table relative to purchasing behaviour
|
# table relative to purchasing behaviour
|
||||||
df_pb = df.groupby("segment")[["prop_purchases_internet", "taux_ouverture_mail", "opt_in"]].mean().reset_index()
|
df_pb = df.groupby("segment")[["prop_purchases_internet", "taux_ouverture_mail", "opt_in"]].mean().reset_index()
|
||||||
|
|
||||||
# concatenation of tables to prepare the plot
|
# concatenation of tables to prepare the plot
|
||||||
df_used = pd.concat([df_pb, df_mp[['share_known_gender', 'share_of_women', 'country_fr']]], axis=1)
|
df_used = pd.concat([df_pb, df_mp[[ 'share_of_women', 'age']]], axis=1)
|
||||||
|
|
||||||
|
# rename columns for the plot
|
||||||
|
df_used = df_used.rename(columns={'taux_ouverture_mail': 'mails_opened', 'prop_purchases_internet': 'purchases_internet'})
|
||||||
|
|
||||||
# visualization
|
# visualization
|
||||||
nb_segments = df_used.shape[0]
|
nb_segments = df_used.shape[0]
|
||||||
categories = list(df_used.drop("segment", axis=1).columns)
|
categories = list(df_used.drop("segment", axis=1).columns)
|
||||||
|
|
||||||
|
var_not_perc = ["age"]
|
||||||
|
|
||||||
# Initialize graphic
|
# Initialize graphic
|
||||||
fig, ax = plt.subplots(2,2, figsize=(25, 20), subplot_kw=dict(polar=True))
|
fig, ax = plt.subplots(2,2, figsize=(20, 20), subplot_kw=dict(polar=True))
|
||||||
|
|
||||||
for index in range(nb_segments) :
|
for index in range(nb_segments) :
|
||||||
row = index // 2 # Division entière pour obtenir le numéro de ligne
|
row = index // 2 # Division entière pour obtenir le numéro de ligne
|
||||||
|
@ -195,7 +200,10 @@ def radar_mp_plot_all(df, type_of_activity) :
|
||||||
# labels
|
# labels
|
||||||
ax[row, col].set_yticklabels([])
|
ax[row, col].set_yticklabels([])
|
||||||
ax[row, col].set_xticks(angles)
|
ax[row, col].set_xticks(angles)
|
||||||
ticks = [categories[i].replace("_"," ") + f"\n({round(100 * tvalues[i],2)}%)" for i in range(len(categories))]
|
|
||||||
|
# define the ticks
|
||||||
|
values_printed = [str(round(tvalues[i],2)) if categories[i] in var_not_perc else f"{round(100 * tvalues[i],2)}%" for i in range(len(categories))]
|
||||||
|
ticks = [categories[i].replace("_"," ") + f"\n({values_printed[i]})" for i in range(len(categories))]
|
||||||
ax[row, col].set_xticklabels(ticks, color="black", size = 20)
|
ax[row, col].set_xticklabels(ticks, color="black", size = 20)
|
||||||
|
|
||||||
ax[row, col].spines['polar'].set_visible(False)
|
ax[row, col].spines['polar'].set_visible(False)
|
||||||
|
@ -203,6 +211,8 @@ def radar_mp_plot_all(df, type_of_activity) :
|
||||||
ax[row, col].set_title(f'Segment {index+1}\n', size = 24)
|
ax[row, col].set_title(f'Segment {index+1}\n', size = 24)
|
||||||
|
|
||||||
fig.suptitle(f"Characteristics of marketing personae of {type_of_activity} companies", size=32)
|
fig.suptitle(f"Characteristics of marketing personae of {type_of_activity} companies", size=32)
|
||||||
|
|
||||||
|
plt.tight_layout()
|
||||||
# plt.show()
|
# plt.show()
|
||||||
|
|
||||||
def known_sociodemo_caracteristics(df, type_of_activity) :
|
def known_sociodemo_caracteristics(df, type_of_activity) :
|
||||||
|
|
Loading…
Reference in New Issue
Block a user