[英]Plotly: How to format numeric yaxis and hover text?
我有一個帶有數字 yaxis 的 python 繪圖圖,它會自動將 yaxis 數字格式化為“k”比例,並且當懸停該點時,會顯示類似“115.277258k”的值。
如何更改比例以顯示 100,000 而不是100k
並將懸停文本格式化以顯示115,2772.58
而不是115.277258k
?
當前使用循環繪制多個子圖。
for i in range(1, allcities.size + 1):
for col in ['total_inflow', 'total_outflow', 'total_withdraw', 'total_account']:
plot_data = hist[hist['city_id'] == allcities[i - 1]]
plot_data = plot_data.merge(datelist, on='balance_date', how='right')
fig.append_trace({'x': plot_data['balance_date'],
'y': round(plot_data[col], 2),
'type': 'scatter',
'mode': 'lines',
'line': dict(color=line_colors[col]),
'showlegend': False,
'name': line_legends[col]
}, i + 1, 1)
謝謝!
您可以像這樣更改go.Scatter()
的懸停go.Scatter()
:
hovertemplate = 'y:%{y:20,.2f}'
您可以使用update_layout(yaxis=dict())
編輯刻度標簽,如下所示:
yaxis=dict(tickformat="20,.2f")
情節:
完整代碼:
import plotly.graph_objects as go
import numpy as np
x = np.arange(10)
fig = go.Figure(data=go.Scatter(x=x**6, y=x**4,
mode='lines+markers',
hovertemplate = '<i>y</i>:%{y:20,.2f}'+ '<br><b>x</b>: %{x}<br>',
fig.update_layout(yaxis=dict(tickformat="20,.2f"),
xaxis=dict(tickformat="20,.2f", tickangle = 0))
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.