[英]Does Plotly similar function like matplotlib fill_between
我正在將一些 matplotlib 代碼轉換為 Plotly。
Plotly 有沒有類似於 matplotlib fill_between
要轉換的代碼
# ax.fill_between(fcst_t, fcst['yhat_lower'], fcst['yhat_upper'],
#
color='#0072B2', alpha=0.2, label='Uncertainty interval')
我可以設法做類似下面的事情,但我想用特定的顏色填充這兩條線之間的區域。
fig.add_trace(
go.Scatter(x=fcst_t,y=forecast['yhat_lower'],fillcolor='grey',mode='lines+markers',name="yhat_lower"),
row=1,col=1
)
fig.add_trace(
go.Scatter(x=fcst_t,y=forecast['yhat_upper'],fillcolor='grey',mode='lines+markers',name="yhat_upper"),
row=1,col=1
)
go.Scatter
有一個fill
關鍵字,可以用來控制填充行為。 您可以在此文檔頁面或鍵入help(go.Scatter)
閱讀更多內容。
import plotly.graph_objects as go
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x) + 2
y2 = np.sin(x / 2) + 8
fig = go.Figure([
go.Scatter(x=x, y=y1),
# fill between the endpoints of this trace and the endpoints of the trace before it
go.Scatter(x=x, y=y2, fill="tonextx"),
])
fig
如果兩條線的點數不同,填充也應該有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.