【发布时间】:2021-12-11 05:52:48
【问题描述】:
import plotly as plotly
from plotly.offline import plot
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
df = pd.DataFrame({'height': [712, 712, 716, 716, 718, np.nan, np.nan, np.nan, np.nan, np.nan],
'moisture': [0.06, 0.19, 0.18, 0.17, 0.18, np.nan, np.nan, np.nan, np.nan, np.nan],
'tasks': ['water', None, None, 'prune', None, None, 'position', None, 'prune', None]},
index=['2020-01-04', '2020-01-05', '2020-01-06', '2020-01-07', '2020-01-08', '2020-01-09',
'2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13'])
df.index.name = 'date'
从df 我想绘制一个“线”图并在所有index date 点上添加一个值出现在df.tasks 列中的点,无论对应的@987654326 中是否有值@row 与否。
我只能用代表高度值的基本线而不是垂直线来绘制“线”图,使用.....
fig = px.line(df, x=df.index, y=df.height)
在此之后,我创建了字典,我认为可以从中生成垂直线......
index_tasks = df[~df.tasks.isnull()]
task_dict = index_tasks.groupby('date')['tasks'].apply(list).to_dict()
但是,即使在浏览了情节文档之后,我也不确定如何继续。
感谢您的阅读,希望您能伸出援助之手。
【问题讨论】:
标签: python dictionary plot plotly