简体   繁体   中英

plotly.express.timeline in subplots

Using Timelines with plotly.express , I can get a working Gantt Chart:

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

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.

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.

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()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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