2 분 소요

Seaborn

Bokeh

import bokeh
from bokeh.plotting import figure
print(bokeh.__version__)
    2.4.3

Line

x = [1, 2, 3, 4, 5]
y = [6, 5, 3, 6, 5]
# 선 생성
p = figure(
    plot_width = 600, 
    plot_height = 300,
    title = "기본 그래프"
)
p.line(x, y)
from bokeh.io import show # 윈도우 브라우저에서 보고자 할 때
show(p)
from bokeh.io import output_notebook # 노트북 상에서 보고자 할 댸
output_notebook()
show(p)

image

from bokeh.io import output_file # 파일로 내보낼 때
from bokeh.io import reset_output # 초기화
output_file("<파일이름>.html")
show(p)
reset_output() # 초기화
output_file("<파일이름2>.html")
nan = float("nan")

p = figure(plot_width = 600, plot_height = 300)
p.line(
    x = [1, 2, 3, 4, 5],
    y = [4, 6, nan, 3, 5],
    line_width = 4,
    color = "rgb(144, 238, 144)",
)
show(p)

image

Step

p = figure(plot_width = 600, plot_height = 300)
p.line(
    x = [1, 2, 3, 4, 5],
    y = [4, 6, 5, 3, 5],
    line_width = 4,
    color = "rgb(144, 238, 144)",
    alpha = 0.6,
    line_dash = "dashed"
)
p.step(
    x = [1, 2, 3, 4, 5],
    y = [4, 6, 5, 3, 5],
    line_width = 3,
    color = "gold",
    mode = "center"  # after or center
)
show(p)

image

Multiple Lines

p = figure(plot_width = 600, plot_height = 300)
p.multi_line(
    [[1, 3, 2], [3, 4, 6, 6]],
    [[2, 1, 4], [4, 7, 8, 5]],
    color = ["green", "orange"],
    alpha = [0.8, 1],
    line_width = [4, 3],
    line_dash = "dotted"
)
show(p)

image

도형

p = figure(plot_width = 600, plot_height = 300)
p.asterisk(
    x = [1, 2, 3, 4, 5],
    y = [2, 5, 1, 9, 5],
)
p.diamond(
    x = [1, 2, 3, 4, 5],
    y = [6, 7, 3, 4, 5],
    size = 15,
    color = "#FF1493",
    angle = 0.8
)
p.square(
    x = [1, 2, 3, 4, 5],
    y = [4, 6, 5, 3, 5],
    size = 20,
    fill_color = "rgb(144, 238, 144)",
    line_color = "rgb(0, 100, 0)"
)
show(p)

image

p = figure(plot_width = 600, plot_height = 300)
p.asterisk(
    x = [1, 2, 3, 4, 5],
    y = [6, 7, 3, 4, 5],
    size = 15,
    color = "green",
)
show(p)

image

p = figure(plot_width = 600, plot_height = 300)
p.circle(
    x = [1, 2, 3, 4, 5],
    y = [6, 7, 3, 4, 5],
    size = 20,
    color = "maroon",
    alpha = 0.5
)
p.line(
    x = [1, 2, 3, 4, 5],
    y = [4, 3, 5, 6, 5]
)

show(p)

image

Custom

p = figure(
    plot_width = 600,
    plot_height = 400,
    x_range = Range1d(-2, 10),
    y_range = Range1d(-1, 7)
)
p.patch(
    x = [2, 3, 5, 8, 6],
    y = [4, 6, 4, 5, 3],
    color = "violet",
)
show(p)

image

p = figure(
    plot_width = 600,
    plot_height = 400,
    x_range = Range1d(-2, 10),
    y_range = Range1d(-1, 7)
)
p.ellipse(
    x = [2, 5],
    y = [3, 6],
    width = [1, 3],
    height = 2,
    color = "tomato",
    line_width = 4,
)
show(p)

image

p = figure(
    plot_width = 600,
    plot_height = 400,
    x_range = Range1d(-2, 10),
    y_range = Range1d(-1, 7)
)
p.hex(
    x = [2, 5],
    y = [3, 6],
    size = [60, 80],
    fill_color = None,
    line_color = "maroon",
    line_width = 4,
    angle = 0.2
)
show(p)

image

p = figure()
p.rect(
    x = [4],
    y = [3],
    width = [6],
    height = [5],
    fill_color = "lightblue",
    line_color = "navy",
    line_width = 2,
    angle = 0.2
)
p.plot_width = 600
p.plot_height = 400
p.x_range = Range1d(-2, 10)
p.y_range = Range1d(-1, 7)
show(p)

image

댓글남기기