import pandas as pd
import numpy as np
from bokeh.charts import Histogram,BoxPlot, output_file, show
from bokeh.io import output_notebook
from bokeh.embed import components
#サンプルデータの作成。dpc点数・科名・dpc期間だけのデータ
ten = np.random.normal(2000,100,5000)
ka = np.random.randint(1,10,5000)
kikan = np.random.randint(1,4,5000)
df = pd.DataFrame({'dpc点数':ten,'科名':ka,'dpc期間':kikan})
df.head(10)
dpc期間 | dpc点数 | 科名 | |
---|---|---|---|
0 | 2 | 1891.498393 | 1 |
1 | 1 | 1933.910512 | 8 |
2 | 2 | 1859.893487 | 7 |
3 | 1 | 1980.984604 | 2 |
4 | 3 | 1966.610687 | 5 |
5 | 1 | 2069.666563 | 5 |
6 | 3 | 1968.111809 | 7 |
7 | 3 | 1771.481786 | 8 |
8 | 2 | 2071.198084 | 4 |
9 | 1 | 1985.846699 | 2 |
#ヒストグラムの作成
hist = Histogram(df, values='dpc点数', title="テスト", plot_width=400,bins = 10)
output_notebook()
show(hist)
#期間別ヒストグラムの作成
hist2 = Histogram(df, values='dpc点数', title="期間別",color='dpc期間',plot_width=400,bins = 10)
output_notebook()
show(hist2)
#科別の箱ひげ図を作成
box = BoxPlot(df, values='dpc点数', title="箱ひげ図",label='科名',color = '科名')
output_notebook()
show(box)