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()