File size: 3,204 Bytes
2090f04 |
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 102 103 104 105 106 107 108 109 110 111 112 113 |
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+10]},
'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(
autosize=False,
width=650,
height=250,
margin=dict(
l=10,
r=10,
b=10,
t=10,
pad=4
),)
return fig
def Naturalness_Plot(Nat_Score, fair_thre=2, good_thre = 4, Upper=5, Lower=0):
'''
Nat_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)
assert Nat_Score >= Lower
assert Nat_Score <= Upper
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+0.4]},
"bar":{'color': color}},
value = Nat_Score,
domain = {'x': [0, 1], 'y': [0, 1]},
)
)
fig.update_layout(
autosize=False,
width=650,
height=250,
margin=dict(
l=10,
r=10,
b=10,
t=10,
pad=4
),)
return fig
# test case Intelligibility_Plot
# x = Intelligibility_Plot(10)
# x.show()
# x = Naturalness_Plot(3.5)
# x.show()
# x = Intelligibility_Plot(50)
# x.show()
# x = Intelligibility_Plot(90)
# x.show()
|