File size: 3,062 Bytes
ffe1030 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
import plotly.express as px
import plotly.graph_objects as go
# Couleurs du Stade Toulousain
STADE_COLORS = {
'primary': '#CC0C13', # Rouge principal
'secondary': '#000000', # Noir
'accent': '#FFFFFF', # Blanc
'light_red': 'rgba(204, 12, 19, 0.2)',
'dark_gray': '#333333'
}
def get_stade_toulousain_colorscale():
"""Palette de couleurs Stade Toulousain"""
return [[0, STADE_COLORS['secondary']], [1, STADE_COLORS['primary']]]
def get_stade_toulousain_colors():
"""Couleurs discrètes pour graphiques multiples"""
return [STADE_COLORS['primary'], STADE_COLORS['secondary'],
STADE_COLORS['dark_gray'], STADE_COLORS['light_red']]
def apply_stade_style(fig, title=None):
"""Applique le style Stade Toulousain à n'importe quel graphique"""
fig.update_layout(
# Fond et papier
plot_bgcolor='rgba(248, 249, 250, 0.5)',
paper_bgcolor='rgba(0,0,0,0)',
# Police et couleurs
font=dict(family='Arial', color=STADE_COLORS['secondary'], size=11),
# Titre
title=dict(
text=title,
font=dict(color=STADE_COLORS['primary'], size=16, family='Arial Black'),
x=0.5,
xanchor='center'
) if title else None,
# Barre de couleur
coloraxis_colorbar=dict(
tickfont=dict(color=STADE_COLORS['secondary'], size=10),
bgcolor='rgba(255,255,255,0.8)',
# bordercolor=STADE_COLORS['primary'],
)
)
# Axes
fig.update_xaxes(
showgrid=True,
gridcolor=STADE_COLORS['light_red'],
gridwidth=1,
zeroline=True,
zerolinecolor=STADE_COLORS['primary'],
zerolinewidth=2,
tickfont=dict(color=STADE_COLORS['secondary'], size=11)
)
fig.update_yaxes(
showgrid=False,
tickfont=dict(color=STADE_COLORS['secondary'], size=11)
)
# Hover personnalisé
fig.update_traces(
hoverlabel=dict(
bgcolor=STADE_COLORS['primary'],
font_color='white',
font_size=12
)
)
return fig
def create_custom_bar_chart(data, x, y, title="", orientation='h', remove_y_title=True):
"""Crée un graphique en barres avec le style Stade Toulousain"""
fig = px.bar(
data,
x=x,
y=y,
orientation=orientation,
color=x if orientation=='h' else y,
color_continuous_scale=get_stade_toulousain_colorscale()
)
# Appliquer le style
fig = apply_stade_style(fig, title)
# Configuration spécifique pour les barres horizontales
if orientation == 'h':
fig.update_layout(
yaxis={
'categoryorder': 'total ascending',
'title': '' if remove_y_title else y
},
xaxis={'title': x.replace('_', ' ').title()}
)
return fig |