我正在使用情节 4.4.1。我想将 x 轴和右侧窗格中的数字格式化为百分比。我已经看到了条形图的例子,但它似乎不适用于子弹图。我错过了什么?
import plotly.graph_objects as go
my_score = 0.81
class_avg = 0.75
fig = go.Figure()
fig.add_trace(go.Indicator(
mode = "number+gauge+delta", value = my_score,
delta = {'reference': class_avg, 'relative' : True,
'increasing':{'color':"green"},
'decreasing':{'color':"red"}
},
domain = {'x': [0.1, 1], 'y': [0.2, 0.9]},
title = {'text': "Math"},
gauge = {
'shape': "bullet",
'axis': {'range': [None, 1]},
'threshold': {
'line': {'color': "red", 'width': 2},
'thickness': 0.75,
'value': class_avg},
'bar': {'color': "black"}}))
fig.update_layout(
title={
'text': "Black Bar is My Score % Correct <br> Red Line is Class Average",
'y':0.85,
'x':0.45,
'xanchor': 'center',
'yanchor': 'top'},
xaxis = dict(
tickformat = '.1%',
title = '% Correct',
fixedrange = True,
hoverformat = '.1%',
showgrid = True),
yaxis = dict(
fixedrange = True,
hoverformat = '.3f',
showgrid = True),
bargap = 0.2,
barmode = 'relative')
fig.show()