将matplotlib图转换为bokeh时间线图?

问题描述

我正在尝试使用bokeh库绘制时间线图。

The image is the result of python code below

import matplotlib.pyplot as plt
import csv

with open('syscall.csv','r') as csvfile :
    rows = list(csv.reader(csvfile,delimiter=','))[1:]
    #rows.sort(key = lambda x: int(x[7])) 
    for row in rows:
        print(row[6])
        alfa=0.8
        renk = 'g'
        start,end,data = int(row[6]),int(row[14]),int(row[5])
        x = [start,end]
        y = [data,data]
        plt.plot(x,y,label=row[0],marker='o',color = renk)
plt.xlabel('time(milliseconds)')
plt.ylabel('Amount of Data(bytes)')
plt.title('VFS and EXT4 layer READ/WRITE graph')
plt.legend(['VR = Red,ER=black,VW=blue,EW=green,vr=%d,er=%d,vw=%d,ew=%d'%(vrc,erc,vwc,ewc)],loc='lower left')
plt.grid(True)
plt.savefig('test.png')
plt.show()

我正在尝试有效使用bokeh的时间线图以可视化我的数据。有人可以帮我解决这个问题,也欢迎任何建议。

亲切的问候, 谢谢

解决方法

好吧,要使用散景图而不是matplotlib,必须组织数据。我无法为您完成此操作,因为我没有您的文件。下面是一个原型,用于将一些数据点绘制为圆形,欢迎您使用。如果不是您想要的,请查看bokeh gallery,因为有一些goog示例。

from bokeh.plotting import output_notebook,figure,output_notebook,show
from bokeh.models import ColumnDataSource

output_notebook()

data = ColumnDataSource({'x':[1,2,3],'y':[10,30,20],'color':['green','red','yellow']
                       })

p = figure(title='VFS and EXT4 layer READ/WRITE graph',x_axis_label = 'time(milliseconds)',y_axis_label = 'Amount of Data(bytes)',)

p.circle(x='x',y='y',color='color',source=data,legend_label='data')

show(p)