Laronix_Recording / local /indicator_plot.py
KevinGeng's picture
add loose threshold/ remove speed limitation
2b3114a
raw
history blame contribute delete
No virus
3.07 kB
import plotly.graph_objects as go
def Intelligibility_Plot(Int_Score, fair_thre=30, good_thre = 70, Upper=100, Lower=0):
'''
Int_Score: a float number between 0 and 100
Upper: the upper bound of the plot
Lower: the lower bound of the plot
'''
# Assert Nat_Score is a float number between 0 and 100
assert isinstance(Int_Score, float|int)
assert Int_Score >= Lower
assert Int_Score <= Upper
# Indicator plot with different colors, under fair_threshold the plot is red, then yellow, then green
# Design 1: Show bar in different colors refer to the threshold
color = "#75DA99"
if Int_Score <= fair_thre:
color = "#F2ADA0"
elif Int_Score <= good_thre:
color = "#e8ee89"
else:
color = "#75DA99"
fig = go.Figure(go.Indicator(
mode="number+gauge",
gauge={'shape': "bullet",
'axis':{'range': [Lower, Upper]},
'bgcolor': 'white',
'bar': {'color': color},
},
value=Int_Score,
domain = {'x': [0, 1], 'y': [0, 1]},
)
)
# # Design 2: Show all thresholds in the background
# fig = go.Figure(go.Indicator(
# mode = "number+gauge",
# gauge = {'shape': "bullet",
# 'axis': {'range': [Lower, Upper]},
# 'bgcolor': 'white',
# 'steps': [
# {'range': [Lower, fair_thre], 'color': "#F2ADA0"},
# {'range': [fair_thre, good_thre], 'color': "#e8ee89"},
# {'range': [good_thre, Upper], 'color': " #75DA99"}],
# 'bar': {'color': "grey"},
# },
# value = Int_Score,
# domain = {'x': [0, 1], 'y': [0, 1]},
# )
# )
fig.update_layout(height=300, width=1000)
return fig
def Naturalness_Plot(Nat_Score, fair_thre=2, good_thre = 4, Upper=5, Lower=1.0):
'''
Int_Score: a float number between 0 and 100
Upper: the upper bound of the plot
Lower: the lower bound of the plot
'''
# Assert Nat_Score is a float number between 0 and 100
assert isinstance(Nat_Score, float|int)
assert Nat_Score >= Lower
assert Nat_Score <= Upper
# Indicator plot with different colors, under fair_threshold the plot is red, then yellow, then green
color = "#75DA99"
if Nat_Score <= fair_thre:
color = "#F2ADA0"
elif Nat_Score <= good_thre:
color = "#e8ee89"
else:
color = "#75DA99"
fig = go.Figure(go.Indicator(
mode="number+gauge",
gauge={'shape': "bullet",
'axis':{'range': [Lower, Upper]},
'bgcolor': 'white',
'bar': {'color': color},
},
value=Nat_Score,
domain = {'x': [0, 1], 'y': [0, 1]},
)
)
fig.update_layout(height=300, width=1000)
return fig
# test case Intelligibility_Plot
x = Intelligibility_Plot(10)
x.show()
x = Intelligibility_Plot(50)
x.show()
x = Intelligibility_Plot(90)
x.show()