【问题标题】:TimeSeries as a box plot with BokehTimeSeries 作为带有 Bokeh 的箱线图
【发布时间】:2015-06-30 01:29:38
【问题描述】:

更新:之前的问题早就解决了,现在可以在类别名称中加上冒号(这个问题已经过时了)



编辑:我所有的问题都是由于我的类别值中有冒号。显然,您的 x/y 值中不能有冒号!

我正在尝试制作显示某些传感器健康状况的箱线图。

1 = 好 0 = 不好

x 轴:传感器 ID y轴:时间戳

我正在使用 python & bokeh,我希望结果看起来像: http://docs.bokeh.org/en/latest/docs/gallery/unemployment.html

但在我的例子中,x 轴是时间戳,而不是一个月。

如何为这些数据设置我的 ColumnDataSource,以便它具有作为 X 轴的时间序列,并将所有值 1 显示为绿色,将 0 显示为红色?

编辑:使用第一个建议中的代码,绘图仍然没有显示任何内容。

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)

编辑 2:显然你必须为 figure() 对象指定一个 x_range 和 y_range ,否则什么都不会绘制。

持续的问题是让情节显示日期时间对象,我不确定散景是否可以处理。如果我的 x 轴由字符串组成,一切正常,但当它们是日期时间/时间戳时则不行。

【问题讨论】:

  • 只需将您的时间戳转换为字符串然后:)

标签: python bokeh


【解决方案1】:

我假设您的数据位于以下形式的数据框中:

timestamp sensor1 sensor2
t1        1       0
t2        0       1

然后从该示例中修改相应的代码部分,您将这样做

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

【讨论】:

  • 感谢您花时间回答。不幸的是,您的解决方案不起作用,或者我没有正确绘制(我已经编辑了我的问题以反映)
猜你喜欢
  • 2017-10-13
  • 2018-09-16
  • 2020-05-27
  • 2015-07-04
  • 1970-01-01
  • 2017-06-29
  • 2011-12-24
  • 2023-03-10
  • 1970-01-01
相关资源
最近更新 更多