Voici un script « clé en main » en Python/Matplotlib qui :
- charge les données ;
- trace les volumes de sessions (barres) pour mobile & desktop, année N vs N-1 ;
- superpose, sur un axe secondaire, les CVR correspondants (lignes) ;
- affiche les transactions en annotation pour garder un visuel lisible.
# ===============================================================
# 0) Packages
# ===============================================================
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("whitegrid")
# ===============================================================
# 1) Données
# ===============================================================
df = pd.DataFrame({
"Mois" : ["Jan", "Fév", "Mars", "Avr", "Mai", "Juin"],
# Sessions
"Sess_mob_N" : [1867621, 1371266, 1475142, 1236306, 1298158, 1127679],
"Sess_mob_N1" : [1795090, 1206481, 1404531, 1276201, 1181579, 1046873],
"Sess_des_N" : [391615, 314684, 328268, 286069, 281546, 258986],
"Sess_des_N1" : [444749, 357657, 371239, 350249, 300340, 252387],
# CVR (en %)
"CVR_mob_N" : [0.80, 0.78, 0.82, 0.87, 0.84, 0.92],
"CVR_mob_N1" : [0.84, 0.77, 0.77, 0.82, 0.86, 0.93],
"CVR_des_N" : [1.60, 1.39, 1.50, 1.49, 1.53, 1.58],
"CVR_des_N1" : [1.63, 1.28, 1.35, 1.38, 1.48, 1.63],
# Transactions globales (N / N-1)
"Trans_N" : [6249, 4387, 4921, 4266, 4302, 4094],
"Trans_N1" : [7252, 4580, 5017, 4818, 4445, 4118]
})
# ===============================================================
# 2) Construction du graphique
# ===============================================================
fig, ax1 = plt.subplots(figsize=(12,7))
# ------------------------- Barres Sessions ---------------------
x = range(len(df))
bar_width = 0.18
# Mobile
ax1.bar([i - 1.5*bar_width for i in x], df["Sess_mob_N"], bar_width,
color="#1f77b4", label="Sessions Mobile (N)")
ax1.bar([i - 0.5*bar_width for i in x], df["Sess_mob_N1"], bar_width,
color="#aec7e8", label="Sessions Mobile (N-1)")
# Desktop
ax1.bar([i + 0.5*bar_width for i in x], df["Sess_des_N"], bar_width,
color="#ff7f0e", label="Sessions Desktop (N)")
ax1.bar([i + 1.5*bar_width for i in x], df["Sess_des_N1"], bar_width,
color="#ffbb78", label="Sessions Desktop (N-1)")
ax1.set_ylabel("Sessions")
ax1.set_xticks(x)
ax1.set_xticklabels(df["Mois"])
ax1.set_title("S1 — Sessions, CVR & Transactions : Mobile vs Desktop (N vs N-1)")
ax1.tick_params(axis='y', labelcolor="black")
# ------------------------- Axe secondaire : CVR -----------------
ax2 = ax1.twinx()
ax2.plot(x, df["CVR_mob_N"], marker="o", color="#005fbf",
label="CVR Mobile (N)")
ax2.plot(x, df["CVR_mob_N1"], marker="o", linestyle="--", color="#89b1e1",
label="CVR Mobile (N-1)")
ax2.plot(x, df["CVR_des_N"], marker="s", color="#d45500",
label="CVR Desktop (N)")
ax2.plot(x, df["CVR_des_N1"], marker="s", linestyle="--", color="#ffad5c",
label="CVR Desktop (N-1)")
ax2.set_ylabel("CVR (%)")
ax2.tick_params(axis='y', labelcolor="black")
ax2.set_ylim(0, 2) # échelle 0-2 %
# ------------------------- Transactions -------------------------
for i, (tN, tN1) in enumerate(zip(df["Trans_N"], df["Trans_N1"])):
ax1.text(i - 0.25, max(df.loc[i, ["Sess_mob_N","Sess_des_N"]])*1.02,
f"Tx N : {tN:,}", fontsize=8, ha="center")
ax1.text(i + 0.25, max(df.loc[i, ["Sess_mob_N1","Sess_des_N1"]])*1.02,
f"Tx N-1 : {tN1:,}", fontsize=8, ha="center", color="gray")
# ------------------------- Légende & layout ---------------------
# On fusionne les légendes des deux axes
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(handles1 + handles2, labels1 + labels2,
loc="upper center", ncol=2, frameon=True, fontsize=9)
plt.tight_layout()
plt.show()