끄적끄적 코딩
article thumbnail

범주형 축 (Categorical Axes)

factors = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
x = np.random.randint(10, 50, size=10)
p = figure(y_range=factors)
p.circle(x, factors, size=20, fill_color="lightblue", line_color="royalblue", line_width=2)
show(p)

 

날짜/시간 축 (Datetime Axes)

애플, 구글 주식 데이터를 통한 예제

from bokeh.sampledata.stocks import AAPL, GOOG

aapl = pd.DataFrame(AAPL)
goog = pd.DataFrame(GOOG)
aapl['date'] = pd.to_datetime(aapl['date'])	#datetime 형식으로 변경
goog['date'] = pd.to_datetime(goog['date'])	#datetime 형식으로 변경
p = figure(plot_width=800, plot_height=250, x_axis_type="datetime")
p.line(aapl['date'], aapl['close'], color='red', alpha=0.5)
p.line(goog['date'], goog['close'], color='blue', alpha=0.5)
show(p)

 

애플 구글, IBM, 마이크로소프트의 주식 데이터를 통한 예제

from bokeh.sampledata.stocks import AAPL, GOOG, IBM, MSFT
from bokeh.palettes import Spectral4

p = figure(plot_width=800, plot_height=250, x_axis_type="datetime")

for data, name, color in zip([AAPL, IBM, MSFT, GOOG], ["AAPL", "IBM", "MSFT", "GOOG"], Spectral4):
  datetime = np.asarray(data['date'], dtype=np.datetime64)	# datetime 지정
  value = np.asarray(data['close'])
  p.line(datetime, value, line_width=1, color=color, alpha=0.8, legend_label=name)

p.legend.location = "top_left"	# 범례 왼쪽 위에 위치
p.legend.click_policy="hide" # 범례 클릭 옵션 : hide

show(p)

 

로그스케일 (Log Scale Axes)

x = np.arange(1, 10, 0.5)
y = [10 ** xx for xx in x]

p = figure(plot_width=400, plot_height=400, y_axis_type="log") # 로그 스케일
p.line(x, y, line_width=1)
p.circle(x, y, fill_color="white", size=5)
show(p)

 

x = np.arange(1, 10, 0.5)
y = [10 ** xx for xx in x]

p = figure(plot_width=400, plot_height=400)
p.line(x, y, line_width=1)
p.circle(x, y, fill_color="white", size=5)
show(p)

.

'bokeh' 카테고리의 다른 글

[bokeh] 데이터 제공  (0) 2020.10.05
[bokeh] 스타일 (Style)  (0) 2020.10.05
[bokeh] 범위 지정 (Setting Ranges)  (0) 2020.10.05
[bokeh] 도형 결합 (Combining Multiple Glyphs)  (0) 2020.10.05
[bokeh] 쐐기, 원호 (Wedges, Arcs)  (0) 2020.10.05

검색 태그