问题描述
基本上,我试图用非常小的数字(例如 0.00000000045
)绘制图表。我需要将它们绘制在 Y 轴上,但我得到的是指数(例如 4.5e-10
)。
这是我的代码:
data_for_df = []
for Trade in parsed["data"]["ethereum"]["dexTrades"]:
data = {
'Date': datetime.datetime.fromisoformat(Trade['timeInterval']['minute'][0:-1]),'AAPL.Open': float(Trade['open_price']),'AAPL.High': float(Trade['maximum_price']),'AAPL.Low': float(Trade['minimum_price']),'AAPL.Close': float(Trade['close_price']),}
data_for_df.append(data)
df = pd.DataFrame.from_dict(data_for_df)
fig = go.figure(
data=[
go.Candlestick(
x=df['Date'],open=df['AAPL.Open'],high=df['AAPL.High'],low=df['AAPL.Low'],close=df['AAPL.Close'],name="WRT/BNB",)
]
)
fig.add_scatter(x=df.Date,y=df['AAPL.Close'],mode='lines',name='Close price',line=dict(color="#ffb3b3"))
fig.update_layout(
yaxis_title="BNB price",xaxis_rangeslider_visible=False,yaxis=dict(
showexponent='none',exponentformat='none'
)
)
fig.show()
在 yaxis
中没有 update_layout
我明白了:
解决方法
您需要使用 'tickformat' 选项而不是 'exponantformat'。
像这样:
yaxis={'title': 'BNB price','tickformat':'e'}
,
所以,找到了。它看起来像
yaxis={'title': 'BNB price','tickformat': ".12f"}
我的错误:
我以前试过用 "{.12f}"
,这是不正确的。