最近需要处理数据可视化,要求可以交互
使用的是bokeh,做一下笔记。
python 安装bokeh
pip install bokeh
下载bokehjs
npm install bokehjs --force
import pandas as pd
from bokeh.plotting import figure
from bokeh.io import output_file, show
df = pd.read_csv("iris.csv")
#df = df.sort_values(by = )
print(df['num'])
#TOOLS = 'hover,crosshair,pan,wheel_zoom,box_zoom,reset,save,box_select'
p = figure(plot_width=800, plot_height=400)
p.line(x="num", y="Petal.Length", source = df)
p.line(x="num", y="Sepal.Length", source = df)
output_file("iris3.html", title="iris")
show(p)
比起matplotlib感觉更高大上一点
如果不能访问外网或者有限制的时候html中没有图像,将bokehjs中的css和js文件复制到html同一文件夹下
原来生成的html为
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-1.1.0.min.css" type="text/css" />
<script type="text/javascript" src="https://cdn.pydata.org/bokeh/release/bokeh-1.1.0.min.js"></script>
替换为
<link rel="stylesheet" href="bokeh.min.css" type="text/css" />
<script type="text/javascript" src="bokeh.min.js"></script>