Big Data with Datashader demo。 The input type can scale normally and display details, but when it is integrated into Django, zooming cannot display specific details
my code
from os.path import join
from pathlib import Path
import bokeh.plotting as bp
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import HoverTool
from bokeh.themes import Theme
from datashader.bokeh_ext import InteractiveImage
import datashader as ds
import pandas as pd
import numpy as np
import datashader.transfer_functions as tf
from utils import matUtil
from ykkj_ai import settings
theme = Theme(filename=join(settings.THEMES_DIR, "theme.yaml"))
data = matUtil.loadmat(Path(join(settings.BASE_DIR, "featrue_bokeh", "1575362779.mat")))["data"]
# 工具
hover = HoverTool(
tooltips=[
("(x值,y值)", "($x, $y)"),
]
)
p = bp.figure(x_axis_type="datetime", x_range=(0, 5), tools=[hover, 'pan', 'wheel_zoom', 'box_zoom', 'save', 'reset'],
y_range=(np.min(data), np.max(data)))
dists = {cat: pd.DataFrame(dict(x=np.arange(0, len(data), 1) / float(44100),
y=data,
val=val, cat=cat))
for x, y, s, val, cat in
[(2, 2, 0.01, 10, "d1"), (2, -2, 0.1, 20, "d2"), (-2, -2, 0.5, 30, "d3"), (-2, 2, 1.0, 40, "d4"),
(0, 0, 3, 50, "d5")]}
df = pd.concat(dists, ignore_index=True)
df["cat"] = df["cat"].astype("category")
def image_callback(x_range, y_range, w, h):
cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
agg = cvs.line(df, 'x', 'y', ds.count_cat('cat'))
img = tf.shade(agg)
print('=========被调用', w, h)
# return tf.dynspread(img, threshold=0.25)
return tf.shade(ds.Canvas().line(df,'x','y'))
InteractiveImage(p, image_callback)
doc = curdoc()
doc.theme = theme
doc.add_root(column(p, sizing_mode='stretch_both'))
doc.title = "信号数据"