끄적끄적 코딩
article thumbnail
Published 2020. 10. 4. 09:13
[bokeh] 라인 플롯 (Line Plots) bokeh

라인 플롯 - 선을 그리는 시각화 모양


단일 플롯 (Single Lines)

x = np.arange(100) # 0 ~ 99
y = np.random.randn(100).cumsum()  # cumsum - 누적합
p = figure(plot_width=400, plot_height=400) # 400 * 400
p.line(x, y, line_width=2) # line - x축은 x값, y축은 y값, line길이 2
show(p)

 

p = figure(plot_width=400, plot_height=400)
p.line(x, y, line_width=2, line_dash="dotted") # line을 점선 형태로
show(p)

 

p = figure(plot_width=400, plot_height=400)
p.line(x, y, line_width=2, line_dash="dashed", color="purple") # line 색 보라색
show(p)

 

실제 데이터를 통한 예제를 위해 sampledata 사용

from bokeh.sampledata.glucose import data
data.tail()

days = data.loc['2010-10-01':'2010-10-10'] #2010-10-01 ~ 2010-10-10
p = figure(x_axis_type="datetime", title="Glocose", plot_height=350, plot_width=800) # x축 type datetime으로 지정
p.xgrid.grid_line_color=None # x축으로 된 gird 제거
p.ygrid.grid_line_alpha=0.5 # y축으로 된 grid 투명도 50%
p.xaxis.axis_label = 'Datetime' # x축 레이블 정보
p.yaxis.axis_label = 'glucose' # y축 레이블 정보
p.line(days.index, days.glucose) # line - x축 days.index, y축 days.glucose
show(p)

 

 

스텝 라인 (Step Lines)

p = figure(plot_width=400, plot_height=400) 
p.step([1, 2, 3, 4, 5], [6, 2, 4, 1, 2], line_width=2, mode="center") # step, mode - 값이 위치하는 곳
show(p)

 

 

다중 라인 (Multiple Lines)

p = figure(plot_width=400, plot_height=400)
p.multi_line([np.arange(10), np.arange(10)],	# multi_line
             [np.random.randn(10).cumsum(), np.random.randn(10).cumsum()],	
             color=["red", "blue"], alpha=[0.5, 0.5], line_width=4) 	# [빨강, 파랑]
show(p)

 

스택 라인 (Stacked Lines)

from bokeh.models import ColumnDataSource	# data를 쉽게 정의하고 입력 할 수 있게 도와줌

source = ColumnDataSource(data=dict(
  x = np.arange(50),
  y1 = np.random.randn(50).cumsum(),
  y2 = np.random.randn(50).cumsum(),
))

p = figure(plot_width=400, plot_height=400)
p.vline_stack(['y1', 'y2'], x='x', color=['green', 'purple'], source=source) # vline_stack, source값 대입
show(p)

.

'bokeh' 카테고리의 다른 글

[bokeh] 영역 (Areas)  (0) 2020.10.05
[bokeh] 막대, 사각형, 육각 타일  (0) 2020.10.04
[bokeh] 산점도(Scatter Plots)  (0) 2020.10.03
[bokeh] 초기설정  (0) 2020.10.03
[bokeh] colab 환경  (0) 2020.10.03

검색 태그