Black Lives Matter. Please consider donating to Black Girls Code today.

Horizontal time series

Hey peeps,

I’m trying to make a chart to show the status of on/off alarms over time. It should be one horizontal bar per alarm, where the colour is green when it’s activated and red when it’s not. It feels wrong to use a Gantt chart for this, as I’d need to create a lot of time events. I just want to supply it with dates and True or False.

Any guidance would be much appreciated.

Thanks!

Hi @oriolgalceran,

Here’s an example to get you started

import plotly.graph_objs as go
fig = go.FigureWidget()
activated = [True, False, False, True]
bar = fig.add_bar(y=[1, 2, 3, 4],
                  x=[1, 3, 2, 4],
                  marker={'color': ['green' if active else 'red' for active in activated]},
                  orientation='h')
fig

Hope that helps!
-Jon

Hey Jon,

Thanks for the quick reply. The thing is that the bars should be continous, so for example if bar 1 was True from 0 to 1 and False from 1 to 4 it should be green from 0 to 1 and then red from 1 to 4.

The format i have is a csv with dates and True or False. So it should be like a time series.

Hi @oriolgalceran,

You can set the starting position of each bar using the base property to position multiple bars per row.

import plotly.graph_objs as go
fig = go.FigureWidget()
activated = [True, False, False, True, False, True]
alarm_number = [1, 2, 3, 3, 1, 2]
start = [0, 0, 1, 2, 1, 3]
duration = [1, 3, 1, 3, 2, 2]

bar = fig.add_bar(y=alarm_number,
                  x=duration,
                  base=start,
                  marker={'color': ['green' if active else 'red' for active in activated]},
                  orientation='h')
fig.layout.barmode = 'stack'
fig

To do this with dates, I think you would set the base property to the start date of the alarm, and then set the x value to the alarm duration in milliseconds.

Hope that helps,
-Jon

Dear @jmmease,

I am also struggling to solve this issue, but I have a slightly different dataset I can’t find a solution to solve it with.

I have a dataset comprised of 14 columns representing 14 wind turbines. The values inside them are:
0 - for not available
1 - for part-time available
2 - for full-time available

I have approx 350k rows as the dataset represents a time-series with 10-min frequency.

I would like to plot a graph where each bar represents a different turbine, each bar spans across the whole timeframe and the status shoud show:
red - for 0
yellow - for 1
and green - for 2

I hope you could help me. I will be really grateful as your solution above with manually specified starting points and durations is impossible to apply.

In my case the duration of each event is 10-mins and its starting point follows the timeframe with the DateTime index.

I am looking for something similar to matplotlib eventplot.

I’ll be grateful for any help.