Plotly Python 中的刻度格式

dsu*_*asa 5 python python-3.x plotly plotly.js plotly-python

我正在尝试将 Plotly 条形图 x 轴格式设置为带有 3 位小数的百分比。

import chart_studio.plotly as py #for plotting
import plotly.graph_objs as go


y = ['niner', 'deuce', 'checker']
x = [0.03, -0.05, 0.075]


fig = go.Figure(go.Bar(y = y, x = x,
            name = 'returns',
            orientation = 'h',
            marker = dict(color = '#003663',
                             line = dict(
                                      color = '#afafaf',
                                      width = 1.5)
                                    )))

fig.update_layout(
        title = 'Why So Hard Plotly?',
        xaxis = dict(
                tickformat = '%.format.%3f',
                title = 'Returns',
                fixedrange = True,
                hoverformat = '.3f',
                showgrid = True), 

        yaxis = dict(

                fixedrange = True,
                hoverformat = '.3f',
                showgrid = True,

        ),     
         bargap = 0.2, 
         barmode = 'relative',             
)
fig.update_yaxes(automargin=True) 
fig.show()
Run Code Online (Sandbox Code Playgroud)

我可以使用 使 y 轴显示为四舍五入的百分比tickformat = '%',但我无法显示更多小数。Plotly d3 文档(对我来说)不清楚如何做到这一点。任何帮助表示赞赏。

提前致谢。

nic*_*ten 7

我相信设置tickformat".3%"应该可以做到。0.512345以这种方式格式化会产生51.235%.

  • 这是一个有用的页面,其中包含刻度格式示例供参考:https://observablehq.com/@d3/d3-format (5认同)