python - Plotly Python - 标签值格式化

标签 python pandas plotly

如何设置标签值的格式,使其显示实际的小数而不是自动设置为微单位?

例如我希望它显示为 0.0001 而不是 100µ,绿色标签中没有自动格式化。

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)

另一个更新:

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

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

最佳答案

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

d3.format("r")(0.0001)

r - decimal notation, rounded to significant digits.

您可以阅读更多相关信息 here :

tickformat (string) default: ""
Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/blob/master/README.md#locale_format

关于python - Plotly Python - 标签值格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48687956/

相关文章:

python - 如何防止执行脚本时打开 HTML 本地文件?

python - 破折号 : how to control graph style via CSS?

python - 如何在 Pytest 中将参数传递给 Selenium 测试函数?

python - 有没有办法将处理图像的 GIMP 步骤转换为 GEGL 函数调用?

python - 'CSV 不存在' - Pandas DataFrame

python - Pandas Dataframe 到 HTML 删除索引

python - 如何在 plotly 中为 ticktext 着色?

Python:开始使用 tk,小部件不在网格上调整大小?

python - 对于无限数据集,每个时期中使用的数据是否相同?

python - 基于另一个数据帧在数据帧中的特定位置插入多列