carolinejean-pierre commited on
Commit
b088181
·
1 Parent(s): 4a27959

Add visualisation function

Browse files
Files changed (1) hide show
  1. src/utils.py +58 -1
src/utils.py CHANGED
@@ -258,4 +258,61 @@ def format_gwp_eq_airplane_paris_nyc(gwp: Quantity) -> Quantity:
258
  gwp_eq = gwp_eq.to("kgCO2eq")
259
  return gwp_eq / AIRPLANE_PARIS_NYC_GWP_EQ####################################################################################### MODELS PARAMETER####################################################################################
260
 
261
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  gwp_eq = gwp_eq.to("kgCO2eq")
259
  return gwp_eq / AIRPLANE_PARIS_NYC_GWP_EQ####################################################################################### MODELS PARAMETER####################################################################################
260
 
261
+ #####################################################################################
262
+ ### VISUALIZATIONS
263
+ #####################################################################################
264
+
265
+ def range_plot (mean_val, min_val, max_val, unit):
266
+
267
+ fig = go.Figure()
268
+
269
+ # Background bar
270
+ fig.add_trace(go.Bar(
271
+ x=[max_val],
272
+ y=[''],
273
+ orientation='h',
274
+ marker=dict(color="#0B3B36"),
275
+ showlegend=False,
276
+ hoverinfo='skip',
277
+ ))
278
+
279
+ # Vertical line
280
+ fig.add_shape(
281
+ type="line",
282
+ x0=mean_val, y0=-1,
283
+ x1=mean_val, y1=1,
284
+ line=dict(color='#00BF63', width=3, dash="solid"),
285
+ #name="Average"
286
+ )
287
+
288
+ # Add labels
289
+ for val, pos, text in zip([max_val, min_val]*2,[0.85,0.85,1.6,1.6], ["Max", "Min", f'{max_val:.3g}{' '}{unit}', f'{min_val:.3g}{' '}{unit}']):
290
+ fig.add_annotation(
291
+ x=val,
292
+ y=-pos,
293
+ text=text,
294
+ showarrow=False,
295
+ font=dict(color="black", size=16)
296
+ )
297
+
298
+ fig.add_annotation(
299
+ x=mean_val,
300
+ y=1.65,
301
+ text=f'{mean_val:.3g}{' '} {unit}',
302
+ showarrow=False,
303
+ font=dict(color="black", size=35)
304
+ )
305
+
306
+ # Layout adjustments
307
+ fig.update_layout(
308
+ height=160,
309
+ width = 400,
310
+ xaxis=dict(range=[min_val, max_val], showgrid=False, showticklabels=False),
311
+ yaxis=dict(showticklabels=False),
312
+ plot_bgcolor='white',
313
+ margin=dict(l=100, r=100, t=0, b=20),
314
+ showlegend=False
315
+ )
316
+
317
+ # Show the plot in Streamlit
318
+ st.plotly_chart(fig, use_container_width=True)