-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_bar_chart.py
53 lines (31 loc) · 1.27 KB
/
generate_bar_chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import matplotlib.pyplot as plt
import pandas as pd
import streamlit as st
def generate_bar_chart(df, title="Revenu et Dépenses",width=400, height=200):
"""
Generates a bar chart for Revenu (blue) and Dépenses (red) from a DataFrame.
Parameters:
- df (pandas.DataFrame): The data containing 'date', 'revenu', and 'depenses' columns.
- title (str): The title of the chart.
"""
if not {'date', 'revenu', 'depenses'}.issubset(df.columns):
raise ValueError("DataFrame must contain 'date', 'revenu', and 'depenses' columns")
if df.index.name != 'date':
df.set_index('date', inplace=True)
ax = df[['revenu', 'depenses']].plot(kind='bar', color=['blue', 'red'], figsize=(10, 6))
plt.title(title)
plt.xlabel("Date")
plt.ylabel("Montant")
plt.xticks(rotation=45, ha='right')
plt.grid(True, linestyle='--', alpha=0.7)
plt.tight_layout()
st.pyplot(plt)
if __name__ == "__main__":
data = {
'date': ['2024-08-01', '2024-08-02', '2024-08-03'],
'revenu': [1000, 1500, 1200],
'depenses': [800, 1200, 1100]
}
df = pd.DataFrame(data)
st.title("Revenu vs Dépenses Bar Chart Example")
generate_bar_chart(df, title="Example: Revenu et Dépenses")