df是這樣的:
X Y Label
0 [16, 37, 38] [7968, 4650, 3615] 0.7
1 [29, 37, 12] [4321, 4650, 1223] 0.8
2 [12, 2, 445] [1264, 3456, 2112] 0.9
這應該在同一個圖上繪制三條線,并將標簽作為連續變數。使用它繪制它的最快和最簡單的方法是什么plotly?
uj5u.com熱心網友回復:
采取這應該在與要求相同的圖上繪制三條線。(這與我想要 df 每一行的子圖的位置不一致)
為每一行創建跟蹤的簡單案例,使用
由標簽定義的連續顏色
import pandas as pd
import plotly.graph_objects as go
from plotly.colors import sample_colorscale
import plotly.express as px
df = pd.DataFrame(
{
"X": [[16, 37, 38], [29, 37, 12], [12, 2, 445]],
"Y": [[7968, 4650, 3615], [4321, 4650, 1223], [1264, 3456, 2112]],
"Label": [0.1, 0.5, 0.9],
}
)
fig = px.scatter(x=[0], y=[0], color=[.5], color_continuous_scale="YlGnBu")
fig = fig.add_traces(
[
go.Scatter(
x=r["X"].explode(),
y=r["Y"].explode(),
name=str(r["Label"].values[0]),
line_color=sample_colorscale("YlGnBu", r["Label"].values[0])[0],
showlegend=False
)
for _, r in df.groupby(df.index)
]
)
fig
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/412437.html
標籤:
下一篇:將一個資料框劃分為多個R中的名稱
