10
10
import humanize
11
11
from wordcloud import WordCloud , get_single_color_func
12
12
13
+
14
+ # Define custom template
15
+ custom_template = {
16
+ "layout" : {
17
+ "autosize" : True ,
18
+ "plot_bgcolor" : "white" ,
19
+ "font" : {"family" : "Roboto, sans-serif" },
20
+ "title" : None ,
21
+ "margin" : dict (l = 0 , r = 0 , b = 0 , t = 0 ),
22
+ }
23
+ }
24
+
25
+
13
26
# Define color sequence for plots
14
27
COLOR_SEQUENCE = ["#D9D9D9" , "#1E2E5C" ]
15
28
@@ -84,26 +97,18 @@ def number_of_tracked_reports_over_time(
84
97
85
98
# Create figure
86
99
fig = px .bar (
87
- data , x = "year" , y = "mnc" , color_discrete_sequence = COLOR_SEQUENCE , text_auto = True
100
+ data , x = "year" , y = "mnc" , text_auto = True , color_discrete_sequence = COLOR_SEQUENCE
88
101
)
89
102
90
103
# Force position and color of bar values
91
104
fig .update_traces (textposition = "outside" , textfont = dict (color = "black" ))
92
105
106
+ # Define axes settings
107
+ fig .update_xaxes (title = None , tickvals = data ["year" ].unique ())
108
+ fig .update_yaxes (title = None , visible = False , range = [0 , data ["mnc" ].max () * 1.1 ])
109
+
93
110
# Update layout settings
94
- fig .update_layout (
95
- autosize = True ,
96
- height = 360 ,
97
- font_family = "Roboto, sans-serif" ,
98
- title = None ,
99
- xaxis = dict (title = None , tickvals = data ["year" ].unique ()),
100
- yaxis = dict (
101
- title = None ,
102
- visible = False ,
103
- ),
104
- plot_bgcolor = "white" ,
105
- margin = dict (l = 0 , r = 0 , b = 0 , t = 0 ),
106
- )
111
+ fig .update_layout (template = custom_template , height = 360 )
107
112
108
113
# Define style of hover on bars
109
114
fig .update_traces (
@@ -178,10 +183,14 @@ def breakdown_of_reports_by_sector(df: pd.DataFrame) -> go.Figure:
178
183
orientation = "h" , # Horizontal orientation
179
184
labels = {"percent" : "Percentage of Companies (%)" , "sector" : "Sector" },
180
185
text = "percent" , # Show the percentage as text label
181
- hover_data = {"unique_company_count" : True , "percent" : ":.2f%" }, # Add tooltip for count and rounded percentage
186
+ hover_data = {
187
+ "unique_company_count" : True ,
188
+ "percent" : ":.2f%" ,
189
+ }, # Add tooltip for count and rounded percentage
182
190
)
183
191
184
- fig .update_layout (title = None )
192
+ # Update layout settings
193
+ fig .update_layout (template = custom_template )
185
194
186
195
return go .Figure (fig )
187
196
@@ -228,8 +237,8 @@ def breakdown_of_reports_by_hq_country(df: pd.DataFrame) -> go.Figure:
228
237
# Add tooltip for count and rounded percentage
229
238
)
230
239
231
- # Update layout to display the title above the chart
232
- fig .update_layout (title = None )
240
+ # Update layout settings
241
+ fig .update_layout (template = custom_template )
233
242
234
243
return go .Figure (fig )
235
244
@@ -269,11 +278,8 @@ def breakdown_of_reports_by_sector_over_time(df: pd.DataFrame) -> go.Figure:
269
278
category_orders = {"Sectors" : chart_order },
270
279
)
271
280
272
- # Reverse the order of legend items
273
- fig .update_layout (
274
- title = None ,
275
- legend = dict (traceorder = "reversed" )
276
- )
281
+ # Update layout settings
282
+ fig .update_layout (template = custom_template , legend = dict (traceorder = "reversed" ))
277
283
278
284
# Adjusting the legend order and formatting the legend labels
279
285
for i , trace in enumerate (fig .data ):
@@ -455,22 +461,19 @@ def top_jurisdictions_revenue(df: pd.DataFrame, company: str, year: int) -> go.F
455
461
x = "total_revenues_%" ,
456
462
y = "jur_name" ,
457
463
orientation = "h" ,
458
- color_discrete_sequence = COLOR_SEQUENCE ,
459
464
text_auto = ".1%" ,
465
+ color_discrete_sequence = COLOR_SEQUENCE ,
460
466
)
461
467
462
468
# Set figure height (min. 480) depending on the number of jurisdictions
463
469
fig_height = max (480 , (48 * len (df ["jur_name" ])))
464
470
471
+ # Update axis layout
472
+ fig .update_xaxes (title = "Percentage of total revenue" , tickformat = ".0%" )
473
+ fig .update_yaxes (title = None )
474
+
465
475
# Update layout settings
466
- fig .update_layout (
467
- font_family = "Roboto" ,
468
- xaxis = dict (title = "Percentage of total revenue" , tickformat = ".0%" ),
469
- yaxis_title = None ,
470
- plot_bgcolor = "white" ,
471
- height = fig_height ,
472
- margin = dict (l = 0 , r = 0 , t = 0 , b = 0 ),
473
- )
476
+ fig .update_layout (template = custom_template , height = fig_height )
474
477
475
478
# Define position of text values
476
479
values_positions = [
@@ -541,18 +544,17 @@ def pretax_profit_and_employees_rank(df: pd.DataFrame, company: str, year: int)
541
544
else :
542
545
max_x_value = 1
543
546
547
+ # Update axis layout
548
+ fig .update_xaxes (title = None , tickformat = ".0%" , range = [0 , max_x_value ])
549
+ fig .update_yaxes (title = None )
550
+
544
551
# Update layout settings
545
552
fig .update_layout (
546
- font_family = "Roboto" ,
547
- title = None ,
548
- xaxis = dict (title = None , tickformat = ".0%" , range = [0 , max_x_value ]),
549
- yaxis_title = None ,
550
553
legend = dict (
551
- x = 0.1 , y = 1.05 , xanchor = "center " , yanchor = "top" , title = dict (text = "" ), orientation = "h"
554
+ orientation = "h" , yanchor = "bottom" , y = 1.01 , xanchor = "left " , x = 0 , title = dict (text = "" )
552
555
),
553
- plot_bgcolor = "white" ,
556
+ template = custom_template ,
554
557
height = fig_height ,
555
- margin = dict (l = 0 , r = 0 , t = 10 , b = 0 ),
556
558
)
557
559
558
560
# Add annotations for NaN values where there should have been a bar
@@ -639,24 +641,17 @@ def pretax_profit_and_profit_per_employee(
639
641
custom_data = ["jur_name" ],
640
642
)
641
643
644
+ # Update axis layout
645
+ fig .update_xaxes (title = "Percentage of profit" , tickformat = ".0%" )
646
+ fig .update_yaxes (title = "Profit per employee" )
647
+
642
648
# Update layout settings
643
649
fig .update_layout (
644
- title = None ,
645
- font_family = "Roboto" ,
646
- autosize = True ,
647
- height = 360 ,
648
- xaxis = dict (
649
- title = "Percentage of profit" ,
650
- tickformat = ".0%" ,
651
- ),
652
- yaxis = dict (
653
- title = "Profit per employee" ,
654
- ),
655
650
legend = dict (
656
- x = 0.1 , y = 1.05 , xanchor = "center " , yanchor = "top" , title = dict (text = "" ), orientation = "h"
651
+ orientation = "h" , yanchor = "bottom" , y = 1.01 , xanchor = "left " , x = 0 , title = dict (text = "" )
657
652
),
658
- plot_bgcolor = "white" ,
659
- margin = dict ( l = 0 , r = 0 , t = 0 , b = 0 ) ,
653
+ template = custom_template ,
654
+ height = 380 ,
660
655
)
661
656
662
657
# Define hover
@@ -739,15 +734,13 @@ def related_and_unrelated_revenues_breakdown(
739
734
text_auto = ".0%" ,
740
735
)
741
736
737
+ # Update axis layout
738
+ fig .update_xaxes (title = None , tickformat = ".0%" )
739
+ fig .update_yaxes (title = None )
740
+
742
741
# Update layout settings
743
742
fig .update_layout (
744
- title = None ,
745
- xaxis = dict (title = None , tickformat = ".0%" ),
746
- yaxis_title = None ,
747
- legend = dict (title = dict (text = "" ), orientation = "h" ),
748
- plot_bgcolor = "white" ,
749
- width = 800 ,
750
- height = 480 ,
743
+ legend = dict (title = dict (text = "" ), orientation = "h" ), template = custom_template
751
744
)
752
745
753
746
# Define position of text values
@@ -915,17 +908,13 @@ def tax_havens_use_evolution(df: pd.DataFrame, company: str) -> go.Figure:
915
908
barmode = "group" ,
916
909
text_auto = ".1%" ,
917
910
)
911
+ # Update axis layout
912
+ fig .update_xaxes (title = None )
913
+ fig .update_yaxes (title = None , tickformat = ".0%" )
918
914
919
915
# Update layout settings
920
916
fig .update_layout (
921
- title = None ,
922
- xaxis_title = None ,
923
- yaxis_title = None ,
924
- yaxis_tickformat = ".0%" ,
925
- legend = dict (title = dict (text = "" ), orientation = "h" ),
926
- plot_bgcolor = "white" ,
927
- width = 800 ,
928
- height = 480 ,
917
+ legend = dict (title = dict (text = "" ), orientation = "h" ), template = custom_template
929
918
)
930
919
931
920
return go .Figure (fig )
@@ -1250,7 +1239,7 @@ def transparency_score_over_time(df: pd.DataFrame, company: str):
1250
1239
1251
1240
# Update layout settings
1252
1241
fig .update_layout (
1253
- title = "Transparency score over time" ,
1242
+ template = custom_template ,
1254
1243
xaxis = dict (title = None , tickvals = df ["year" ].unique ()),
1255
1244
yaxis = dict (
1256
1245
title = None ,
@@ -1262,9 +1251,6 @@ def transparency_score_over_time(df: pd.DataFrame, company: str):
1262
1251
tickvals = [0 , 25 , 50 , 75 , 100 ],
1263
1252
ticktext = [0 , "" , "" , "" , 100 ],
1264
1253
),
1265
- plot_bgcolor = "white" ,
1266
- width = 800 ,
1267
- height = 480 ,
1268
1254
)
1269
1255
1270
1256
# Force position and color of bar values
0 commit comments