Mam następujący mały przykład skrypt wykorzystuj numpy i bokeh:HoverTool dla wielu serii danych w bokeh wykres punktowy
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()
Problemem jest to, że narzędzie aktywowanych działa tylko dla krzywej cosinus ale nie dla sinus.
Wiem, że jedna z opcji byłoby wykreślić obu serii togehter i zmienić kolor punktów danych cosinus:
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()
colors = np.array([blue.repeat(len(y1)),red.repeat(len(y1))]).flatten()
s1 = fig.scatter(x=x,y=y,color=colors,size=10,legend='sine & cosine')
s1.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
bp.show()
Ale potem stracić pozycję Legenda do drugiego koloru.
Jak mogę ustawić kursor na obu zestawach danych i zobaczyć odpowiednią etykietkę?
Dzięki!
Max
Wielkie dzięki! Działa jak marzenie! – Max
Mam ten błąd: AttributeError: obiekt 'generator' nie ma atrybutu 'tooltips'. Zaktualizowałem swój bokeh za pomocą następującego polecenia: pip install --pre -i https://pypi.anaconda.org/bokeh/channel/dev/simple bokeh --extra-index-url https://pypi.python.org/ simple/ –
Ten sam numer co Hamid na 0.10 – dranxo