I am close. So I am trying to add x and y coordinates to the
hover tool also, but I am ending up with two hover tools that
overlap where I just want one. I am assuming I am making 2
HoverTool objects. Is there a way to create one HoverTool object
and just add tooltips to the same HoverTool object? What
complicates things is that one HoverTool object is being made in
that for loop, so not sure how to add a tooltip to that one.
You should be setting one line in each iteration of the loop.
You seem to have written out all the lines unnecessarily.
Either write them out or use a for-loop, don't do both.
Thanks Sarah.
I have to admit, I am not familiar with that lower level
style API on Bokeh. I guess that this style is considered
"plotting with basic gylphs" per this documentation:
http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html
<http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html>
I've been studying Bokeh's high level charts api per this
documentation since I like to do with DataFrame data
structure instead of having to construct the data with dicts:
http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html
Where examples show I just simply pass in a DataFrame.
From your example, I can only deduce or infer that I have to
use a loop to draw each individual line or DataFrame's
column by specifying the corresponding x and y values, is
that correct?
For example, I tried:
from bokeh.charts import Line, output_notebook, show
from bokeh.models import HoverTool
from bokeh.plotting import figure, ColumnDataSource
import pandas as pd
import numpy as np)
output_notebook()
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B',
'C', 'D', 'E'])
source = ColumnDataSource(df)
p = figure(plot_width=400, plot_height=400)
for column in df.columns:
line = p.line(x=df.index, y='A', source=source)
line = p.line(x=df.index, y='B', source=source)
line = p.line(x=df.index, y='C', source=source)
line = p.line(x=df.index, y='D', source=source)
p.add_tools(HoverTool(tooltips="This is %s" % column,
renderers=[line]))
output_notebook()
show(p)
It drew the line charts, but the hover tool only worked for
one of the lines.
I also can't seem to find documentation on what the
internals of the ColumnDataSource looks like when I
instantiate it or pass it with a DataFrame.
If currently, the only way to do the hover tool containing
the column names is by using the lower level style api, then
I will probably issue a feature request at the github repo
to allow for this using the high level api. I just can't
see myself trying to do all that for column names in the
hover tooltip. I don't think it is worth it for me then. In comparison to plotly, plotly generates the hover tool
tips for you using their high level api style using
cufflinks which very convenient:
Redirecting…
<https://plot.ly/ipython-notebooks/cufflinks/>
- Daniel
On Thursday, April 28, 2016 at 1:07:35 AM UTC-4, Sarah Bird >>> wrote:
Hi Daniel,
The best way to think about it is that Bokeh is really
set-up to be powered by your columns.
If you have a column, you can use it to power many
different aspects of bokeh - the size, position, color,
opacity, .... of your points.
Each point/shapeis a row.
So in your hover tooltip, you can specify @column_name.
As each point is a row then as you hover, the tooltip
will pick off the value for that row of aparticular column.
Lines are these funny things where the "thing" is the
whole column.
What you were hoping to do is completely reasonable, but
is not naturally bokeh-ish if that makes sense.
There is another thing "multi-line" where each row can
hold the points of a line - this could be a solution
except that hit-testing doesn't work for multi-line and
so there's no hover for multi-line.
Sorry you've stumbled in a funny area. As I said, this
is a great request, and is even hinting at a need for
some other kind of api for line-type things.
Here's the code to do what you need.
data = {
x = [1,2, 3],
col1 = [2, 4, 5],
col2 = [4, 6, 7]
}
source = ColumnDataSource(data)
p = figure()
for column in ['col1', 'col2']:
line = p.line(x='x', y='col1', source=source)
p.add_tools(HoverTool(tooltips="This is %s" %
column, renderers=[line]))
data could just as easily be a DataFrame, I just wrote
it like this for clarity
best,
bird
On 4/27/16 7:04 PM, Daniel wrote:
Thanks Sarah. Not sure I'm getting you, but it's
probably because I am not well versed in Bokeh yet. I'll have to learn it better and get back with you. I
was hoping I would just simply pass df.columns to the
tooltips somehow. Since bokeh is touted to be tightly
integrated with pandas data frames, thought it would be
that easy or at least not having to do a looping construct.
On Tuesday, April 26, 2016 at 11:45:47 PM UTC-4, Sarah >>>> Bird wrote:
Hi,
That's a nice feature, unfortunately we don't
support it right now. Can I suggest u open a github
issue.
It is possible to do it though.
I would probably start with p = figure(), make one
ColumnDataSource, the do a for loop over your
categories, then in each one do :
1) line = p.line(...) specifying your column
2) p.add_tools(HoverTool(tooltips="cat name",
renderers=[line]))
Sorry, for the brevity, I'm on my phone. Hope that
makes sense.
Sarah Bird
sb...@continuum.io
On Apr 25, 2016, at 8:50 AM, Daniel >>>> <[email protected]> wrote:
Hello,
I would like to be able to identify individual
chart series with the hover tool. I want the
column name/series name to show up on the hover
tool. I looked at the documentation, but I
couldn't find any that shows how to work with
dataframe.
Here's what I have so far:
Bokeh dataframe hover example · GitHub
<https://gist.github.com/anonymous/1eab3bea584bb4145cecbbdb4cea8a38>
Thanks in advance!
- Daniel
-- You received this message because you are
subscribed to the Google Groups "Bokeh Discussion
- Public" group.
To unsubscribe from this group and stop receiving
emails from it, send an email to
bokeh+un...@continuum.io.
To post to this group, send email to
bo...@continuum.io.
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/bokeh/dcad6d64-22af-4ec1-9190-166e6f3b5b43%40continuum.io
<http://continuum.io/d/msgid/bokeh/dcad6d64-22af-4ec1-9190-166e6f3b5b43%40continuum.io>\.
For more options, visit
https://groups.google.com/a/continuum.io/d/optout
<http://continuum.io/d/optout>\.
-- You received this message because you are subscribed to
the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving
emails from it, send an email to bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/bokeh/78f7fff1-4794-4970-a55e-d62c94510627%40continuum.io
<http://continuum.io/d/msgid/bokeh/78f7fff1-4794-4970-a55e-d62c94510627%40continuum.io>\.
For more options, visit
https://groups.google.com/a/continuum.io/d/optout
<https://groups.google.com/a/continuum.io/d/optout>\.
--
*Sarah Bird*
*/Developer, Bokeh/*
Continuum Analytics <http://continuum.io>
-- You received this message because you are subscribed to the
Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/bokeh/76450073-b7ce-4d77-8db3-0ac537bb6b70%40continuum.io\.
For more options, visit
https://groups.google.com/a/continuum.io/d/optout
<https://groups.google.com/a/continuum.io/d/optout>\.