Timeline plot changes into the Bar plot

When I create and plot a single timeline graph, the output is correct:


However, when I combine it with another heatmap plot, the time data on the X-axis becomes numerical and the plot is incorrect:

I figured that the timeline plot object is a β€œBar” type, thus its values changed:

Is there any way I could combine plotly express timeline plot with graph_object heatmap without distorting graph properties?
Part of the code:

fig1 = go.Figure(px.timeline(df, x_start="Start", x_end="End", y='telescope',color='Event'))
#fig1,show()
fig2= go.Figure(go.Heatmap(
        z=block,
        x=x,
        y=['clouds'],
        colorscale='Blues_r',
        zmin=-20,
        zmax=-10))

fig.append_trace(fig2.data[0],row=1,col=1)
fig.update_traces(showscale=False)

for i in range(len(fig1.data)):
    fig.append_trace(fig1.data[i],row=2,col=1)

fig.update_layout(title_text="Stacked Subplots")

fig.show()

Hi Roman,

Welcome to the forum!

As you might be aware plotly express actually returns the graph object packed up. More info here

Every Plotly Express function uses graph objects internally and returns a plotly.graph_objects.Figure instance.

Having said that, what you are trying to do is pack graph object within graph object and putting heatmap together. My question would be is there any specific reason you are trying to do that? Why not treat both separately?

Best,

Shahzeb

Hi, Shahzeb

Thank you for your reply. I’m very new to the plotly and now I seem to understand what graph object is in plotly. So there is really no need to put the timeline plot into go.Figure(). However, I want to create a subplot of two figures. The only way I see I can do it so far is by appending traces, but when I do that, the timeline plot gets treated as a graph_objects.Bar and the time values for the X-axis are converted to fit in that parameter. I could be wrong in understanding this and I’m trying to find a way to append my timeline plot to the subplots without distorting the data.

HI @roman_aa , maybe this helps:

Hi,
I tried doing this:

fig1 = px.timeline(df, x_start="Start", x_end="End", y='telescope',color='Event')
fig1.add_heatmap(
    z=block,
    x=x,
    y=['clouds'],
    colorscale='Blues_r',
    zmin=-20,
    zmax=-10)

But it doesn’t produce any plot. If I add heatmap to a blank Figure, it outputs the heatmap plot.