728x90
데이터 직접 제공
x = [1, 2, 3, 4, 5]
y = [4, 5, 2, 4, 6]
p = figure(plot_width=400, plot_height=400)
p.circle(x, y)
show(p)
ColumnDataSource
- 앱 이름과 데이터 목록 사이의 매핑
- Bokeh 플롯의 핵심으로 플롯에서 글리프의 시각화된 데이터 제공
- DataTable과 같은 여러 플롯과 위젯간의 데이터를 쉽게 공유
from bokeh.models import ColumnDataSource
data = {'x': [1, 2, 3, 4, 5],
'y': [4, 5, 2, 4, 6]}
source = ColumnDataSource(data=data)
p = figure(plot_width=400, plot_height=400)
p.circle(x='x', y='y', source=source)
show(p)
from bokeh.sampledata.iris import flowers
source =ColumnDataSource(flowers)
p = figure(plot_width=400, plot_height=400)
p.circle(x='petal_length', y='petal_width', source=source)
show(p)
p = figure(plot_width=400, plot_height=400)
p.circle(x='petal_length', y='petal_width', source=flowers)
show(p)
변환 (Transformations)
from bokeh.palettes import Category20c
from bokeh.transform import cumsum
pop = {'서울특별시': 9720846,
'부산광역시': 3404423,
'인천광역시': 2947217,
'대구광역시': 2427954,
'대전광역시': 1471040,
'광주광역시': 1455048}
data = pd.Series(pop).reset_index(name='population').rename(columns={'index':'city'})
data['color'] = Category20c[len(pop)]
data['angle'] = data['population']/data['population'].sum() * 2 * np.pi
p = figure(plot_height=350, toolbar_location=None,
tools="hover", tooltips="@city: @population")
p.wedge(x=0, y=1, radius=0.4,
start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend_field='city', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color=None
show(p)
from bokeh.transform import linear_cmap
N = 2000
data = dict(x=np.random.random(size=N) * 100,
y=np.random.random(size=N) * 100,
r=np.random.random(size=N) * 2)
p = figure()
p.circle('x', 'y', radius='r', source=data, fill_alpha=0.5,
color=linear_cmap('x', 'Viridis256', 0, 100))
show(p)
.
'bokeh' 카테고리의 다른 글
[bokeh] 레이아웃 (Layout) (0) | 2020.10.05 |
---|---|
[bokeh] 주석 (Annotations) (0) | 2020.10.05 |
[bokeh] 스타일 (Style) (0) | 2020.10.05 |
[bokeh] 축 유형 지정 (Specifying Axis Types) (0) | 2020.10.05 |
[bokeh] 범위 지정 (Setting Ranges) (0) | 2020.10.05 |