Skip to content
Snippets Groups Projects
Commit 5976329d authored by Hu Marilyne's avatar Hu Marilyne
Browse files

update new fonctionnality

parent 174d010a
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import numpy as np
import pandas as pd
```
%% Cell type:code id: tags:
``` python
df = pd.read_excel('df_cfa_anonyme.xlsx')
```
%% Cell type:code id: tags:
``` python
df
```
%% Output
denomination_cfa count numero_color name_legend
0 CFA_1 44 0 couleur 1
1 CFA_2 47 1 couleur 2
2 CFA_3 64 1 couleur 2
3 CFA_4 67 3 couleur 4
4 CFA_5 67 0 couleur 1
.. ... ... ... ...
95 CFA_96 58 0 couleur 1
96 CFA_97 23 3 couleur 4
97 CFA_98 79 1 couleur 2
98 CFA_99 13 1 couleur 2
99 CFA_100 85 4 couleur 5
[100 rows x 4 columns]
File added
......@@ -36,7 +36,7 @@ def display() :
# bloc sur les infos du dataframe
st.subheader('Information sur les données :')
with st.expander("📊 Aperçu du DataFrame"):
with st.expander("📊 Aperçu"):
st.markdown(f"**Dimensions :** {df.shape[0]} lignes × {df.shape[1]} colonnes")
st.markdown("**Colonnes disponibles :**")
st.write(list(df.columns))
......@@ -66,25 +66,43 @@ def display() :
else:
title = None
x_choice = st.checkbox("Voulez-vous nommer l'axe des abscisses ?")
if x_choice:
xlabel = st.text_input("Entrez le nom de l'axe des abscisses :", key="xlabel_input")
else:
xlabel = None
model_graph = utils_graph.plot_graph(df = df.loc[:nb_line-1, :], x = col_x, y = col_y)
y_choice = st.checkbox("Voulez-vous nommer l'axe des ordonnées ?")
if y_choice:
ylabel = st.text_input("Entrez le nom de l'axe des ordonnées :", key="ylabel_input")
else:
ylabel = None
col_nombre, col_pourcentage = st.columns(2)
with col_nombre :
x_choice = st.checkbox("Voulez-vous nommer l'axe des abscisses ?", key = "xlabel_choice")
if x_choice:
xlabel = st.text_input("Entrez le nom de l'axe des abscisses :", key="xlabel_input")
else:
xlabel = None
nombre_choice = st.checkbox('Mettre la valeur ?')
if nombre_choice :
nombre = st.selectbox('Nom de la colonne des valeurs :', columns)
else :
nombre = None
with col_pourcentage :
y_choice = st.checkbox("Voulez-vous nommer l'axe des ordonnées ?", key = "ylabel_choice")
if y_choice:
ylabel = st.text_input("Entrez le nom de l'axe des ordonnées :", key="ylabel_input")
else:
ylabel = None
pourcentage_choice = st.checkbox('Mettre le pourcentage ?')
if pourcentage_choice :
pourcentage = st.selectbox('Nom de la colonne des pourcentages :', columns)
else :
pourcentage = None
model_graph = utils_graph.plot_graph(df = df.loc[:nb_line-1, :], x = col_x, y = col_y)
legend_choice = st.checkbox('Voulez-vous mettre une légende de couleurs ?')
#annotation = st.checkbox('Voulez-cous mettre une annotation ?')
#if annotation :
# col_nombre = st.selectbox('Colonne des valeurs absolues', columns)
if legend_choice:
col_color = st.selectbox('Choisir la colonne des numéros de couleurs', columns)
......@@ -120,9 +138,12 @@ def display() :
legend_indices=legend_indices,
title= title,
xlabel= xlabel,
ylabel= ylabel
ylabel= ylabel,
show = False
)
model_graph.annotation(pourcentage= pourcentage, Nombre= nombre)
st.pyplot(barh)
except Exception as e:
......@@ -130,18 +151,17 @@ def display() :
else:
# Tracer sans légende
barh = model_graph.barh_subplot(title= title, xlabel= xlabel, ylabel= ylabel)
barh = model_graph.barh_subplot(title= title, xlabel= xlabel, ylabel= ylabel, show=False)
model_graph.annotation(pourcentage= pourcentage, Nombre= nombre)
st.pyplot(barh)
# Sauvegarde du graphique dans un buffer en mémoire
img_buffer = BytesIO()
barh.savefig(img_buffer, format='png', dpi=300, bbox_inches='tight')
img_buffer.seek(0) # Revenir au début du buffer
# Bouton de téléchargement
st.download_button(
label="📥 Télécharger le graphique",
data=img_buffer,
file_name="mon_graphique.png",
mime="image/png"
)
if 'barh' in locals():
img_buffer = BytesIO()
barh.savefig(img_buffer, format='png', dpi=300, bbox_inches='tight')
img_buffer.seek(0)
st.download_button(
label="📥 Télécharger le graphique",
data=img_buffer,
file_name="mon_graphique.png",
mime="image/png")
\ No newline at end of file
......@@ -21,4 +21,5 @@ streamlit==1.40.0
tqdm==4.66.5
openpyxl==3.1.5
geopandas==1.0.1
mapclassify==2.8.1
\ No newline at end of file
mapclassify==2.8.1
io
\ No newline at end of file
File added
This diff is collapsed.
......@@ -21,7 +21,7 @@ class plot_graph() :
def barh_subplot(self, title = None, xlabel = None, ylabel = None,
path = None, yticklabels = None, xticklabels = None, colors = None,
legend_list = None, title_legend = None, show = True, force_new_fig= True,
legend_indices=None):
legend_indices=None, pourcentage = None, Nombre = None):
# couleurs des barres
if colors in self.df.columns and not self.df[colors].empty:
......@@ -108,6 +108,8 @@ class plot_graph() :
text = f'{self.df.loc[n,Nombre]} ({self.df.loc[n,pourcentage]} %)'
self.ax.text(width * 1.01 if not np.isnan(width) else 0 , bar.get_y() + bar.get_height() / 2,
text, va='center', ha='left', color='gray', fontsize=9)
return self.fig
def encadrer(self) :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment