Plotly Python - 标签值格式

时间:2018-02-08 14:35:10

标签: python pandas plotly

如何格式化标签值以便显示实际小数而不是自动格式化为微单位?

E.g。而不是100μ我希望它显示为0.0001,绿色标签中没有自动格式化。

See the green label

更新12/2/18:

这是一些简洁的数据(macd_output变量):

                         macd  macdsignal      macdhist
datetime                                         
2018-02-12 19:44:00 -0.002401   -0.002316 -8.433693e-05
2018-02-12 19:45:00 -0.002353   -0.002325 -2.734004e-05
2018-02-12 19:46:00 -0.002107   -0.002271  1.641191e-04
2018-02-12 19:47:00 -0.002040   -0.002213  1.732582e-04
2018-02-12 19:48:00 -0.001814   -0.002113  2.990831e-04
2018-02-12 19:49:00 -0.001934   -0.002068  1.344275e-04
2018-02-12 19:50:00 -0.001814   -0.002005  1.910672e-04
2018-02-12 19:51:00 -0.002187   -0.002050 -1.370391e-04
2018-02-12 19:52:00 -0.002438   -0.002147 -2.903001e-04
2018-02-12 19:53:00 -0.003135   -0.002394 -7.411783e-04
2018-02-12 19:54:00 -0.003450   -0.002658 -7.918092e-04
2018-02-12 19:55:00 -0.003242   -0.002804 -4.379292e-04
2018-02-12 19:56:00 -0.003066   -0.002870 -1.962050e-04
2018-02-12 19:57:00 -0.003105   -0.002929 -1.769048e-04
2018-02-12 19:58:00 -0.002929   -0.002929 -6.099654e-07

这是用于生成绘图的python代码部分:

...
macd_output = MACD(ohlcv,fastperiod=params['macd_parameters']['fast'], slowperiod=params['macd_parameters']['slow'], signalperiod=params['macd_parameters']['signal'])

print macd_output

macdhist = go.Bar(
    x=macd_output.index,
    y=macd_output.macdhist
)

macd = go.Scatter(
    x=macd_output.index,
    y=macd_output.macd
)

macdsignal = go.Scatter(
    x=macd_output.index,
    y=macd_output.macdsignal
)

fig = tools.make_subplots(rows=1, cols=1)

fig.append_trace(macdhist, 1, 1)
fig.append_trace(macd, 1, 1)
fig.append_trace(macdsignal, 1, 1)


update_dict = dict(
    xaxis = dict(
        rangeslider = dict(
            visible = False
        ),
        showgrid=True,
    )
)

print fig['layout'].update(update_dict)


plotly.offline.iplot(fig)

另一个更新:

感谢Anne的回答。这对我有用:

fig['layout']['yaxis1'].update(tickformat="0.5r")

1 个答案:

答案 0 :(得分:2)

我认为你需要使用d3格式的标志:

d3.format("r")(0.0001)
  

r - 十进制表示法,四舍五入为有效数字。

您可以详细了解here

  

tickformat(字符串)默认值:""
  设置刻度标签格式规则   使用d3格式化迷你语言,它们非常类似于   蟒蛇。   有关数字,请参阅:   https://github.com/d3/d3-format/blob/master/README.md#locale_format