pan0ramic
pan0ramic

Reputation: 183

TimeSeries as a box plot with Bokeh

UPDATE: The previous issue was long resolved, it is now possible to have category names with colons in them (this question is obsolete)



Edit: All of my problems were due to having colons within my category values. Apparently you cannot have colons in your x/y values!

I'm trying to make box plot which would show the health of some sensors.

1 = good 0 = bad

x-axis: sensor ID y-axis: timestamp

I'm using python & bokeh and I would like the result to look something like: http://docs.bokeh.org/en/latest/docs/gallery/unemployment.html

But in my case the x-axis is timestamp and not a month.

How do I setup my ColumnDataSource for this data so that it has a time-series as an X axis and shows all values of 1 as green and 0 as red?

Edit: Using the code from the first suggestion, the plot still doesn't show anything.

source = ColumnDataSource(data=dict(sensor=sensor, timestamp=timestamp,
                                    color=color, status=status))    
p = figure()
p.rect("timestamp", "sensor", 1, 1, source=source, color="color", line_color=None)

Edit 2: apparently you have to specify an x_range and y_range to the figure() object or else nothing will plot.

The continuing issue is getting the plot to show datetime objects, which I'm not sure bokeh can handle. Everything works fine if my x-axis consists of string, but not when they are datetimes/timestamps.

Upvotes: 1

Views: 1126

Answers (1)

maxymoo
maxymoo

Reputation: 36545

I'll assume that your data is in a data frame of the form:

timestamp sensor1 sensor2
t1        1       0
t2        0       1

Then modifying the appropriate section of code from that example, you would do this

timestamp = list(data['timestamp'])
sensor = ['sensor1','sensor2']
colors = ["red", "green"]

# Set up the data for plotting. We will need to have values for every
# pair of year/month names. Map the rate to a color.
sensor= []
timestamp= []
color = []
status = []
for y in timestamp:
    for m in sensor:
        sensor.append(m)
        timestamp.append(y)
        sensor_status = data[m][y]
        status.append(sensor_status)
        color.append(colors[sensor_status])

source = ColumnDataSource(
    data=dict(sensor=sensor, timestamp=timestamp, color=color, status=status)
)

Upvotes: 1

Related Questions