我想将10000行添加到
bokeh
基于每条线的两个点绘制。一个接一个的添加速度非常慢,可能需要一个小时。有没有办法加快速度?
import pandas as pd
import numpy as np
from bokeh.plotting import figure, show, output_file
output_file('temp.html')
p = figure(plot_width=500, plot_height=400)
df = pd.DataFrame(np.random.randint(0,100,size=(10000, 4)), columns=['x1', 'x2', 'y1', 'y2'])
print df
for index, row in df.iterrows():
p.line([row['x1'], row['x2']], [row['y1'], row['y2']], line_width=2)
show(p)
编辑:
具有多行
import pandas as pd
from bokeh.models.glyphs import MultiLine
from bokeh.models import ColumnDataSource
import numpy as np
from bokeh.plotting import figure, show, output_file
output_file('temp.html')
p = figure(plot_width=500, plot_height=400,
)
df = pd.DataFrame(np.random.randint(0, 100, size=(10000, 4)), columns=['x1', 'x2', 'y1', 'y2'])
source = ColumnDataSource(dict(
xs=df[['x1', 'x2']].as_matrix(),
ys=df[['y1', 'y2']].as_matrix(),
)
)
glyph = MultiLine(xs="xs", ys="ys", line_color="#8073ac", line_width=2)
p.add_glyph(source, glyph)
show(p)