[029量化交易] python互交式显示

这篇博客展示了如何利用Python的Bokeh库创建不同类型的交互式图形,包括散点图、圆圈图、线图和柱状图。通过实例化图形对象、设置颜色和大小,以及添加 HoverTool,使得数据可视化更具交互性。示例中还涉及到了随机数据的生成和数据读取。
摘要由CSDN通过智能技术生成
# 导入模块
from bokeh.plotting import figure, output_file, show
from bokeh.palettes import magma
import numpy as np
import random

c = np.random.randint(0, 10, size=10)
d = np.random.randint(0, 10, size=10)
# 实例化图形对象
graph = figure(title="Bokeh Scatter Graph")
# 读取数据库
# data = pd.read_csv("tips.csv")
color = magma(256)
# 绘制图形
graph.scatter(1, 1, color=color)
graph.scatter(2, 2, color=magma(100))
graph.scatter(3, 3, color=magma(200))
graph.scatter(c, d, color=magma(np.random.randint(0, 256)))

# 展示模型
show(graph)
import numpy.random
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool

x = numpy.random.randn(500)
y = numpy.random.randn(500)
hover = HoverTool()
hover.tooltips = [("(x,y)", "($x, $y)")]

p = figure(tools=[hover])
p.circle(x, y, color='red', size=14, alpha=0.4)

show(p)

在这里插入图片描述

from bokeh.plotting import figure, output_file, show

# output to static HTML file
# output_file("line.html")

# 创建画布
p = figure(plot_width=400, plot_height=400)

# 根据x,y坐标绘制愿(大小、颜色、透明度)
# p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
# # add a square renderer with a size, color, and alpha
# p.square([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], size=20, color="olive", alpha=0.5)
# x,y坐标点及线宽  单条折线
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
# # add a steps renderer
# p.step([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2, mode="center")
# 线段 或射线
p.segment(x0=[1, 2, 3], y0=[1, 2, 3], x1=[1.2, 2.4, 3.1],
          y1=[1.2, 2.5, 3.7], color="#F4A582", line_width=3)
# 显示绘制结果
show(p)

在这里插入图片描述

from bokeh.plotting import figure, show, output_file

p = figure(plot_width=400, plot_height=400)
p.vbar(x=[1, 2, 3], width=0.5, bottom=[0.1, 0.2, 0.3],
       top=[1.2, 2.5, 3.7], color="firebrick")
show(p)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值