我有以下小例子脚本使用numpy和bokeh:
import numpy as np
import bokeh.plotting as bp
from bokeh.objects import HoverTool
bp.output_file('test.html')
fig = bp.figure(tools="reset,hover")
x = np.linspace(0,2*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
s1 = fig.scatter(x=x,y=y1,color='#0000ff',size=10,legend='sine')
s1.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
s2 = fig.scatter(x=x,y=y2,color='#ff0000',size=10,legend='cosine')
s2.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
bp.show()
Run Code Online (Sandbox Code Playgroud)
问题是悬停工具仅适用于余弦曲线,但不适用于正弦曲线.
我知道一个选项是绘制两个系列,并更改余弦数据点的颜色:
import numpy as np
import bokeh.plotting as bp
from bokeh.objects import HoverTool
bp.output_file('test.html')
fig = bp.figure(tools="reset,hover")
x = np.linspace(0,2*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
x = np.array([x,x]).flatten()
y = np.array([y1,y2]).flatten()
blue = np.array('#0000ff').flatten()
red = np.array('#ff0000').flatten() …Run Code Online (Sandbox Code Playgroud) 我在 javascript 中有一个 Date() 对象数组,我想计算每天的事件数。
下面是一个例子:
我所拥有的是:
Array [ Date 2014-12-04T10:30:20.000Z, Date 2014-12-05T11:04:58.056Z, Date 2014-12-05T11:04:58.056Z, Date 2014-12-05T11:04:58.056Z ]
Run Code Online (Sandbox Code Playgroud)
我想要的是:
Array [{date: '2014-12-04', counts: 1}, {date: '2014-12-05', counts: 3}]
Run Code Online (Sandbox Code Playgroud)
非常感谢!
最大限度