设置绘图语言文本的格式

2024-05-28 18:08:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些数据放在一个绘图仪上。不确定我是如何得到一个四舍五入的数字的,但我希望文本中显示完整和准确的值,而不是仅显示1k,例如,我的数据现在应该显示$1001.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}}]
                         }})

Tags: 数据文本addgonumbervaluemodedomain
1条回答
网友
1楼 · 发布于 2024-05-28 18:08:27

选择“常规”作为数字格式。见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}}))

enter image description here

相关问题 更多 >

    热门问题