Skip to content

Incorrect height of coloured px.timeline bars #2684

Closed
@dsm054

Description

@dsm054

In 4.9.0, the following code:

df = pd.DataFrame([{'row': 'A',
  'start_time': '2020-08-04 06:00:01',
  'end_time': '2020-08-04 06:06:01',
  'status': 'succeeded'},
 {'row': 'A',
  'start_time': '2020-08-04 07:00:01',
  'end_time': '2020-08-04 07:05:01',
  'status': 'failed'},
 {'row': 'A',
  'start_time': '2020-08-04 08:00:01',
  'end_time': '2020-08-04 08:06:01',
  'status': 'succeeded'},
 {'row': 'B',
  'start_time': '2020-08-04 06:44:11',
  'end_time': '2020-08-04 06:53:22',
  'status': 'succeeded'},
 {'row': 'B',
  'start_time': '2020-08-04 07:01:58',
  'end_time': '2020-08-04 07:07:48',
  'status': 'succeeded'},
 {'row': 'C',
  'start_time': '2020-08-04 06:38:56',
  'end_time': '2020-08-04 06:44:59',
  'status': 'succeeded'},
 {'row': 'C',
  'start_time': '2020-08-04 06:59:00',
  'end_time': '2020-08-04 07:05:00',
  'status': 'failed'}])

fig = px.timeline(df, x_start="start_time", x_end="end_time", y="row", color="status")
fig.show()

is giving me

image

where the rows coloured red have the wrong height. Perturbing the order seems to help things, in particular sorting by status.

Looking at the sizes of the bars and the underlying json makes me wonder if when it's overlaying the two, it's scaling everything independently, and forgetting that B is even there:

  {'alignmentgroup': 'True',
   'base': ['2020-08-04 07:00:01', '2020-08-04 06:59:00'],
   'hovertemplate': 'status=failed<br>start_time=%{base}<br>end_time=%{x}<br>row=%{y}<extra></extra>',
   'legendgroup': 'failed',
   'marker': {'color': '#EF553B'},
   'name': 'failed',
   'offsetgroup': 'failed',
   'orientation': 'h',
   'showlegend': True,
   'textposition': 'auto',
   'type': 'bar',
   'x': [300000.0, 360000.0],
   'xaxis': 'x',
   'y': ['A', 'C'],
   'yaxis': 'y'}],

If so, faking nondisplayable rows should help, and it seems to:

fake = pd.DataFrame.from_records([{"row": row, "status": status, "start_time": np.nan, "end_time": np.nan} for row in df.row.unique() for status in df.status.unique()])
fig = px.timeline(df.append(fake), x_start="start_time", x_end="end_time", y="row", color="status")
fig.show()

image

which also seems to fix my production case, but preferably would be handled on the plotly side. :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions