2017-12-26 15 views
0

각 줄마다 두 점을 기준으로 bokeh 플롯에 10,000 줄을 추가하고 싶습니다. 1을 1 씩 추가하면 속도가 매우 느리고 최대 1 시간이 소요될 수 있습니다. 이 속도를 높이는 방법이 있습니까?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) 

답변

2

편집 : 단일 세그먼트 라인이 특정 응용 프로그램에 대한 최선의 해결책은 벡터화 segment 글리프 방법을 사용하는 것입니다.

보케 (Bokeh)는 이러한 용도로 사용하기에 적합한 도구는 아닙니다. 모든 종류의 상호 작용 기능을 지원하기 위해 Bokeh는 글리프 당 더 많은 데이터를 사용하여 더 적은 글리프에 대해 명시 적으로 최적화됩니다. 새로운 글리프마다 고정 오버 헤드가 발생하고 Bokeh만으로는 10000 개의 글리프가 결코 합리적이지 않습니다. 한 가지 옵션은 line에 대한 수천 개의 고유 한 호출 대신 모든 회선에 대한 모든 데이터가있는 multi_line이라는 단일 호출을 만드는 것일 수 있습니다. 그러나 더 큰 데이터 세트 (수십억 개까지)를 시각화하는 데 유용하며 Bokeh와 완벽하게 통합되어 이러한 데이터 세트에 대한 상호 작용을 제공하는 Datashader을 볼 수도 있습니다.

+0

감사합니다. 나는 Datashader를 살펴볼 것이지만, 지금은 Multiline을 시도하고 싶다. 이 문서 사용 https://bokeh.pydata.org/en/latest/docs/reference/models/glyphs/multi_line.html. 업데이트 된 코드로 원래 질문을 편집했지만 지금은 그냥 빈 차트를 얻었습니다 – user2242044

+0

사실, 데이터는 항상 시작/끝 및 다른 점이없는 항상 단일 세그먼트 선입니까? 만약 그렇다면 당신은'segment'를 사용해야합니다. 이것은 그 종류의 비주얼을 벡터화하기 위해서 존재하며,'multi_line'보다 데이터를 준비하기 쉽습니다. https://bokeh.pydata.org/en/latest/docs/reference/plotting. html # bokeh.plotting.figure.Figure.segment – bigreddot

+0

예, 데이터 프레임의 각 행은 x0, x1, y0, y1을 나타냅니다. 설명서를 빠르게 살펴 봤는데 올바른 응용 프로그램처럼 보입니다. – user2242044