格式化 Plotly Gauge 文本

Formating Plotly Guage Text

我有一些数据要放在 Plotly 仪表上。不确定我是如何设法得到一个四舍五入的数字的,但我希望在文本中显示完整而准确的值,而不仅仅是 1k,例如我的数据现在应该显示 $1,001.50,但它显示的是 1k。

不太担心使用 k 的“刻度”,只是文本。

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Indicator(
    domain = {'row': 1, 'column': 0},
    value = 1001.50,
    mode = "gauge+number",
    title = {'text': "Total Donations"},
    delta = {'reference': 46000},
    gauge = {'axis': {'range': [None, 46000]},
             'threshold' : {
                 'line': {'color': "red", 'width': 4},
                 'thickness': 0.75,
                 'value': 40000
             }}))

fig.add_trace(go.Indicator(
    mode = "number+delta",
    value = 540,
    number = {'prefix': "$"},
    delta = {'position': "top", 'reference': 450},

    domain = {'row': 1, 'column': 1}))

fig.update_layout(
    grid = {'rows': 1, 'columns': 2, 'pattern': "independent"},
    template = {'data' : {'indicator': [{
        'title': {'text': "Donations this Month"},
        'mode' : "number+delta+gauge",
        'delta' : {'reference': 90}}]
                         }})

Select 一般为数字格式。参见 here

fig.add_trace(go.Indicator(
    domain = {'row': 1, 'column': 0},
    value = 1001.50,
    mode = "gauge+number",
    number = {'valueformat':"g"},
    title = {'text': "Total Donations"},
    delta = {'reference': 46000},
    gauge = {'axis': {'range': [None, 46000]},
             'threshold' : {'line': {'color': "red", 'width': 4}, 'thickness': 0.75, 'value': 40000}}))