Created
May 19, 2026 06:29
-
-
Save empet/52847b658bcd50d3926cb341b325b714 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import plotly.graph_objects as go | |
| from plotly.subplots import make_subplots | |
| def get_pl_fig(df:pd.DataFrame, plot_title:str) -> go.Figure: | |
| x = ['Impozit venit<br> colectat', | |
| 'Venituri<br>proprii', | |
| 'Chelt<br>pers admin', | |
| 'Chelt<br>pers total', | |
| 'Chelt<br>functionare', | |
| 'Chelt<br>dezvoltare'] | |
| N = len(df) | |
| V = df.values | |
| colors =["#CC79A7"]+["#009E73",] * 2 + ["#D55E00"]*3+["#0072B2"] | |
| titles =[f'{V[k, 0]}, {V[k,1]} locuitori, primar {V[k,N-1]}' for k in range(N)] | |
| if N%2: | |
| r = N//2 +1 | |
| K = N-1 | |
| else: | |
| r = N//2 | |
| K = N | |
| fig = make_subplots(rows=r, cols=2, horizontal_spacing=0.08, | |
| vertical_spacing=0.05, subplot_titles=titles+['']) | |
| j=1 | |
| for k in range(0, K, 2): | |
| fig.add_trace(go.Bar(x=x, y=V[k, 2:], marker_color=colors[1:], | |
| text=[f'{v} Mil' for v in V[k,2:]], textposition='inside', | |
| hovertext=" ", name=V[k,0]), j,1) | |
| fig.add_trace(go.Bar(x=x, y=V[k+1, 2:], marker_color=colors[1:], | |
| text=[f'{v} Mil' for v in V[k+1,2:]], textposition='inside', | |
| hovertext=" ", name=V[k+1,0]), j,2) | |
| j=j+1 | |
| if K == N-1: | |
| fig.add_trace(go.Bar(x=x, y=V[K, 2:], marker_color=colors[1:], | |
| text=[f'{v} Mil' for v in V[K,2:]], | |
| textposition='inside', hovertext=" ", name=V[K,0]), j,1) | |
| fig.update_layout(title_text=plot_title, | |
| title_x=0.5, width=1000, height=1600, font_family="Balto", | |
| font_size=11, bargap=0.1, font_color='black', showlegend=False); | |
| fig.update_layout(yaxis_title='Milioane lei', yaxis2_title='Milioane lei', yaxis3_title='Milioane lei', | |
| yaxis4_title='Milioane lei', | |
| yaxis5_title='Milioane lei', yaxis6_title='Milioane lei', yaxis7_title='Milioane lei', yaxis8_title='Milioane lei', | |
| yaxis9_title='Milioane lei', | |
| ) | |
| return fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment