-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.py
More file actions
85 lines (74 loc) · 2.43 KB
/
Copy pathbase.py
File metadata and controls
85 lines (74 loc) · 2.43 KB
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
#!/usr/bin/env python3
"""Visualization functions for InfiniBench dashboard."""
import plotly.graph_objects as go
import pandas as pd
from typing import Optional
import streamlit as st
def create_gauge_chart(
value: float,
max_value: float,
title: str,
color: str = "blue",
unit: str = "",
decimals: Optional[int] = None, # optional
) -> go.Figure:
"""Create a gauge chart for single metric visualization."""
if decimals is None:
if value < 10:
decimals = 2
elif value < 100:
decimals = 1
else:
decimals = 0
fig = go.Figure(
go.Indicator(
mode="gauge+number",
value=value,
domain={"x": [0, 1], "y": [0.05, 0.85]},
title={"text": title, "font": {"size": 18}},
number={
"suffix": f" {unit}",
"font": {"size": 36},
"valueformat": f".{decimals}f",
},
gauge={
"axis": {"range": [0, max_value], "tickformat": f".{decimals}f"},
"bar": {"color": color},
"steps": [
{"range": [0, max_value * 0.6], "color": "lightgray"},
{"range": [max_value * 0.6, max_value * 0.8], "color": "gray"},
{"range": [max_value * 0.8, max_value], "color": "darkgray"},
],
"threshold": {
"line": {"color": "red", "width": 4},
"thickness": 0.75,
"value": max_value * 0.9,
},
},
)
)
fig.update_layout(height=260, margin=dict(t=20, b=0, l=10, r=10))
return fig
def plot_timeseries_auto(
df: pd.DataFrame, title: str = "Timeseries", y_log_scale: bool = False
) -> go.Figure:
"""Generic plot for 2-column timeseries CSV."""
fig = go.Figure()
if df is None or df.empty or len(df.columns) < 2:
fig.update_layout(title=f"{title} (no data)")
return fig
xcol = df.columns[0]
ycol = df.columns[1]
fig.add_trace(go.Scatter(x=df[xcol], y=df[ycol], mode="lines+markers", name=ycol))
fig.update_layout(
title=title,
xaxis_title=str(xcol),
yaxis_title=str(ycol),
template="plotly_white",
height=420,
hovermode="x unified",
)
fig.update_yaxes(rangemode="tozero")
if y_log_scale:
fig.update_yaxes(type="log")
return fig