答案 0 :(得分:0)
针对仍在寻找答案的人:
一些绘图。graph_objects基础首先:
图形由三部分组成:数据(要绘制的迹线),布局(要在其上绘制数据的布局),框架(数据+用于循环的布局)
要回答您的问题以在左侧包含文本,您将必须将文本写为注释(布局)。要在右边包含两个图表,请使用子图(数据)。要使用滑块选择更新它们,您将必须使用框架更新它们。每个帧都有对应于该滑块位置的“数据+布局”。
通用代码流:
我们假设:
#Import plotly graph object
import plotly.graph_objects as go
#Getting different dates
dates = df['Dates'].unique().tolist()
#Plotting first instance
data=[]
#Fig 1
data_dict1 = {{
"x": list(df["X"]),
"y": list(df["Y1"]),
"type":"scatter"},
"ncol":2,"nrow":1 #Subplot location
}
#Fig 2
data_dict2 = {
"x": list(df["X"]),
"y": list(df["Y2"]),
"type":"scatter",
"ncol":2,"nrow":2 #Subplot location
}
data = [data_dict1,data_dict2] #combining both plots
#Layout and slider
layout = {
"sliders" : [{
#Enter required slider layout
,"steps": [] #should include this line in slider
}],
"annotations":[ {
#Input required annotations
}]
} # layout ends
#making Frames
frames =[]
for date in dates:
frame = {"data": [], "name": str(date),"layout":{"annotations":[]}} # Saving each data frame
dataset = df[df[Dates]==date] #subsetting data for a date
# Create charts for this subset data
#Fig 1
data_dict1 = {{
"x": list(dataset["X"]),
"y": list(dataset["Y1"]),
"type":"scatter"},
"ncol":2,"nrow":1 #Subplot location
}
#Fig 2
data_dict2 = {
"x": list(dataset["X"]),
"y": list(dataset["Y2"]),
"type":"scatter",
"ncol":2,"nrow":2 #Subplot location
}
#Adding this data to frame
frame["data"] = [data_dict1,data_dict2]
# Creating lines to be displayed using annotations
annote1 = {
#Add data for line 1
}
annote2 = {
#Add data for line 2
}
annote3 = {
#Add data for line 3
}
annote4 = {
#Add data for line 4
}
#Adding all annotations lines to frame
frame["layout"]["annotations"] = [annote1,annote2,annote3,annote4]
#Combinig all frames
frames.append(frame)
#Updating slider step
slider_step = {
"label": date,
"method": "update"}
#Adding step to layout slider
layout["sliders"][0]["steps"].append(slider_step)
#Combine everything
fig = go.Figure(data =data,layout = layout, frames =frames)
#View in browser
plot(fig, auto_open=True)
希望逻辑流程清楚!