[英]How to Make Event Plot using Python Bokeh Library?
I am trying to make event plot using Bokeh Library.我正在尝试使用 Bokeh Library 制作事件 plot。 I know it is possible using matplotlib.pyplot.eventplot , But I need more interactivity features that is available in Bokeh我知道可以使用matplotlib.pyplot.eventplot ,但我需要 Bokeh 中提供的更多交互功能
I came across the screenshot of such a chart in this Website .我在这个网站上看到了这样一张图表的截图。 So it must be possible in Bokeh.所以在散景中一定是可能的。
How do I make a similar plot using Bokeh Library?如何使用 Bokeh Library 制作类似的 plot?
The idea is very basic.这个想法是非常基本的。 You can use the rect()
function of the figure object, where you have to define x
, y
and width
.您可以使用图 object 的rect()
function,您必须在其中定义x
、 y
和width
。 In your case the figure should have an x-axis
in datetime
-format.在您的情况下,该图应具有datetime
格式的x-axis
。 The width is your duration of on task.宽度是您的任务持续时间。
Minimal example最小的例子
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
df = pd.DataFrame({'y':[1, 2, 3, 4],
'start':[0, 1, 1, 10],
'duration':[1, 2, 1, 5],
'color':['green', 'red', 'blue', 'red']
})
>>>df
y start duration color
0 1 0 1 green
1 2 1 2 red
2 3 1 1 blue
3 4 10 5 red
p = figure(
width=350,
height=350,
title="Task Stream",
toolbar_location="above",
x_axis_type="datetime",
)
p.rect(
source=ColumnDataSource(df),
x="start",
y="y",
width="duration",
height=0.4,
fill_color="color",
line_color="color",
)
show(p)
Output Output
Comment评论
As I mentionend in the comment, the figure you have shared is generated using the dask package
which internally uses bokeh
.正如我在评论中提到的那样,您共享的图形是使用内部使用bokeh
的dask package
生成的。 They use the same idea I described above, but of course the dask project offers much more than this on figure and maby solves more than one problem you have.他们使用我上面描述的相同想法,但当然 dask 项目提供的远不止这个数字,并且可能解决的问题不止一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.