简体   繁体   English

子图中的 plotly.express.timeline

[英]plotly.express.timeline in subplots

Using Timelines with plotly.express , I can get a working Gantt Chart:时间线与 plotly.express 一起使用,我可以获得一个有效的甘特图:

import plotly.express as px
import pandas as pd

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
fig.show()

在此处输入图像描述

Following advice from here , I try to add it to a subplot with shared_xaxes = True根据此处的建议,我尝试将其添加到带有shared_xaxes = True的子图中

from plotly.subplots import make_subplots

fig_sub = make_subplots(rows=2, shared_xaxes=True)
fig_sub.append_trace(fig['data'][0], row=1, col=1)
fig_sub.append_trace(fig['data'][0], row=2, col=1)
fig_sub.show()

在此处输入图像描述

But it treats it like a graph_objects and doesn't display a Gantt chart.但它像对待 graph_objects 一样对待它,并不显示甘特图。

Does anyone have any workarounds or suggestionts?有没有人有任何解决方法或建议?

It is unclear why this is the case, but it appears that the date has been de-formatted, so once again, setting the date in the x-axis format will restore the timeline.目前还不清楚为什么会这样,但似乎日期被反格式化了,所以再次将日期设置为 x 轴格式将恢复时间轴。

from plotly.subplots import make_subplots

fig_sub = make_subplots(rows=2, shared_xaxes=True)
fig_sub.append_trace(fig['data'][0], row=1, col=1)
fig_sub.append_trace(fig['data'][0], row=2, col=1)

fig_sub.update_xaxes(type='date')
fig_sub.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM