Eric2mangel commited on
Commit
10d269d
·
verified ·
1 Parent(s): 15bcfd9

Upload app.py

Browse files

Pour résoudre le graphique qui vibre

Files changed (1) hide show
  1. app.py +49 -20
app.py CHANGED
@@ -140,35 +140,64 @@ with tab1:
140
  col1, col2 = st.columns(2)
141
 
142
  # Heatmap corrélation brute (triangle inférieur)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  with col1:
144
- st.write(f"**Corrélation brute ({corr_type})**")
145
- mask_raw = np.triu(np.ones_like(corr_raw, dtype=bool))
146
- fig, ax = plt.subplots(figsize=(5.5, 4))
147
- sns.heatmap(corr_raw, annot=True, cmap="coolwarm", center=0, ax=ax,
148
- mask=mask_raw, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
149
- plt.tight_layout()
150
- st.pyplot(fig)
151
-
152
- # Heatmap corrélation partielle (triangle inférieur)
 
153
  with col2:
154
  st.write(f"**Corrélation partielle ({corr_type})**")
155
  mask_partial = np.triu(np.ones_like(corr_partial, dtype=bool))
156
- fig2, ax2 = plt.subplots(figsize=(5.5, 4))
157
  sns.heatmap(corr_partial, annot=True, cmap="coolwarm", center=0, ax=ax2,
158
  mask=mask_partial, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
159
- plt.tight_layout()
160
- st.pyplot(fig2)
 
161
 
162
- # Graphique des différences (pleine largeur en dessous)
 
163
  st.write("**Différences (Partielle - Brute)**")
164
  fig3, ax3 = plt.subplots(figsize=(12, 2.2))
165
- colors = ['#d7191c' if x < 0 else '#2b83ba' for x in df_diff['Différence']]
166
- ax3.barh(df_diff['Paire'], df_diff['Différence'], color=colors, height=0.55)
167
- ax3.axvline(0, color='black', linewidth=0.8, linestyle='--')
168
- ax3.set_xlabel('Différence de corrélation', fontsize=8)
169
- ax3.tick_params(axis='both', labelsize=7.5)
170
- ax3.grid(axis='x', alpha=0.3, linestyle=':')
171
- plt.tight_layout()
172
  st.pyplot(fig3)
173
 
174
  st.caption("🔵 Corrélation renforcée après contrôle | 🔴 Corrélation affaiblie après contrôle")
 
140
  col1, col2 = st.columns(2)
141
 
142
  # Heatmap corrélation brute (triangle inférieur)
143
+ # with col1:
144
+ # st.write(f"**Corrélation brute ({corr_type})**")
145
+ # mask_raw = np.triu(np.ones_like(corr_raw, dtype=bool))
146
+ # fig, ax = plt.subplots(figsize=(5.5, 4))
147
+ # sns.heatmap(corr_raw, annot=True, cmap="coolwarm", center=0, ax=ax,
148
+ # mask=mask_raw, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
149
+ # plt.tight_layout()
150
+ # st.pyplot(fig)
151
+
152
+ # # Heatmap corrélation partielle (triangle inférieur)
153
+ # with col2:
154
+ # st.write(f"**Corrélation partielle ({corr_type})**")
155
+ # mask_partial = np.triu(np.ones_like(corr_partial, dtype=bool))
156
+ # fig2, ax2 = plt.subplots(figsize=(5.5, 4))
157
+ # sns.heatmap(corr_partial, annot=True, cmap="coolwarm", center=0, ax=ax2,
158
+ # mask=mask_partial, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
159
+ # plt.tight_layout()
160
+ # st.pyplot(fig2)
161
+
162
+ # # Graphique des différences (pleine largeur en dessous)
163
+ # st.write("**Différences (Partielle - Brute)**")
164
+ # fig3, ax3 = plt.subplots(figsize=(12, 2.2))
165
+ # colors = ['#d7191c' if x < 0 else '#2b83ba' for x in df_diff['Différence']]
166
+ # ax3.barh(df_diff['Paire'], df_diff['Différence'], color=colors, height=0.55)
167
+ # ax3.axvline(0, color='black', linewidth=0.8, linestyle='--')
168
+ # ax3.set_xlabel('Différence de corrélation', fontsize=8)
169
+ # ax3.tick_params(axis='both', labelsize=7.5)
170
+ # ax3.grid(axis='x', alpha=0.3, linestyle=':')
171
+ # plt.tight_layout()
172
+ # st.pyplot(fig3)
173
+
174
  with col1:
175
+ st.write(f"**Corrélation brute ({corr_type})**")
176
+ mask_raw = np.triu(np.ones_like(corr_raw, dtype=bool))
177
+ fig, ax = plt.subplots(figsize=(5, 4)) # Diminuez un peu la taille pour la place
178
+ sns.heatmap(corr_raw, annot=True, cmap="coolwarm", center=0, ax=ax,
179
+ mask=mask_raw, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
180
+ ax.tick_params(axis='both', labelsize=8) # Ajout pour fixer la taille de la police
181
+ # RETRAIT de plt.tight_layout()
182
+ st.pyplot(fig, use_container_width=False) # **IMPORTANT : Forcer la taille fixe**
183
+
184
+ # --- COLONNE 2 : CORRÉLATION PARTIELLE ---
185
  with col2:
186
  st.write(f"**Corrélation partielle ({corr_type})**")
187
  mask_partial = np.triu(np.ones_like(corr_partial, dtype=bool))
188
+ fig2, ax2 = plt.subplots(figsize=(5, 4)) # Même taille que fig
189
  sns.heatmap(corr_partial, annot=True, cmap="coolwarm", center=0, ax=ax2,
190
  mask=mask_partial, square=True, vmin=-1, vmax=1, cbar_kws={'shrink': 0.75}, annot_kws={'size': 9})
191
+ ax2.tick_params(axis='both', labelsize=8) # Ajout pour fixer la taille de la police
192
+ # RETRAIT de plt.tight_layout()
193
+ st.pyplot(fig2, use_container_width=False) # **IMPORTANT : Forcer la taille fixe**
194
 
195
+ # --- GRAPHIQUE DES DIFFÉRENCES (Celui-ci est souvent moins problématique) ---
196
+ # Vous pouvez garder plt.tight_layout() ici ou le remplacer par ax3.set_... si le problème persiste.
197
  st.write("**Différences (Partielle - Brute)**")
198
  fig3, ax3 = plt.subplots(figsize=(12, 2.2))
199
+ # ... (le reste du code du barh reste inchangé)
200
+ plt.tight_layout()
 
 
 
 
 
201
  st.pyplot(fig3)
202
 
203
  st.caption("🔵 Corrélation renforcée après contrôle | 🔴 Corrélation affaiblie après contrôle")