python - Plotly Python 中的刻度格式

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

我可以使用 tickformat = '%' 使 y 轴显示为四舍五入的百分比, 但我不能让更多的小数出现。 Plotly d3 文档(对我而言)不清楚如何执行此操作。感谢您的帮助。

提前致谢。

最佳答案

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

关于python - Plotly Python 中的刻度格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57561902/

相关文章:

python - 使用python操作excel 2007文件

python - 如何获取 youtube 混合播放列表?

python - 为什么正则表达式可以理解没有 r 前缀的\n?

python - 为什么我收到 "RuntimeError: This event loop is already running"

javascript - 条形图的厚度

python - 使用 Python 在终端中生成音频铃

python - 如何找到不包含特定字符串的任何匹配项?

python - 分配一个新列,该列动态地在 numpy 数组的索引上使用指数函数

r - 向可绘制的条形图添加水平线

r - 如何使用 plotly subplots() 删除重复的图例条目