HoverTool with TimeSeries chart (bokeh v0.11.1)

I am new to bokeh and was following the example in the documentation for TimeSeries with customizations for practice and have run into an issue with HoverTool. Can someone assist in correctly formatting both a pandas.tslib.Timestamp object and a numpy.float64 object so they are not display in scientific notation. I would like to see a HoverTool with the “Stock Name”, “Date”, and “Adj Close” (price). My code follows:

coding: utf-8

In[1]:

import pandas as pd

from bokeh.charts import TimeSeries, show, output_file, vplot, output_notebook

output_notebook()

In[2]:

read in the S&P 500 Index Fund from the Yahoo Finance API

GSPC = pd.read_csv(“https://ichart.yahoo.com/table.csv?s=^GSPC”,

    parse_dates=['Date'])

FBIDX = pd.read_csv(“https://ichart.yahoo.com/table.csv?s=FBIDX”,

    parse_dates=['Date'])

NDX = pd.read_csv(“https://ichart.yahoo.com/table.csv?s=^NDX”,

    parse_dates=['Date'])

SO = pd.read_csv(“https://ichart.yahoo.com/table.csv?s=SO”,

    parse_dates=['Date'])

show sample data

print(‘GSPC’)

print(GSPC.head())

print()

print(‘FBIDX’)

print(FBIDX.head())

print()

print(‘NDX’)

print(NDX.head())

print()

print(‘SO’)

print(SO.head())

In[10]:

data = dict(

Date = GSPC['Date'],

GSPC = GSPC['Adj Close'],

FBIDX = FBIDX['Adj Close'],

NDX = NDX['Adj Close'],

SO = SO['Adj Close'],

)

print(type(data[‘Date’][0]))

print(type(data[‘GSPC’][0]))

In[12]:

from bokeh.models import HoverTool

hover = HoverTool(

    tooltips = [

        ("Date", "$x"),

        ("Adj Close", "$y"),

    ]

)

ts_stocks = TimeSeries(data,

    x = 'Date', y = ['GSPC', 'FBIDX', 'NDX', 'SO'],

    color = ['cadetblue', 'firebrick', 'limegreen', 'hotpink'], 

    tools=['box_zoom', 'pan', 'save', hover, 'resize', 'reset', 'wheel_zoom'],

    title = 'Stock Time Series', 

    ylabel = 'Stock Prices', legend=True

)

show(ts_stocks)

Thanks in advance for any help.

Brad

D oes this discussion help:

···

https://github.com/bokeh/bokeh/issues/4347
On 5/24/16 6:14 AM, Brad Hudson wrote:

    I am new to bokeh and was following the example in

the documentation for TimeSeries with customizations for
practice and have run into an issue with HoverTool. Can someone
assist in correctly formatting both a pandas.tslib.Timestamp
object and a numpy.float64 object so they are not display in
scientific notation. I would like to see a HoverTool with the
“Stock Name”, “Date”, and “Adj Close” (price). My code follows:

coding: utf-8

In[1]:

import pandas as pd

          from bokeh.charts import TimeSeries, show,

output_file, vplot, output_notebook

output_notebook()

In[2]:

          # read in the S&P 500 Index Fund from

the Yahoo Finance API

          GSPC =

pd.read_csv(,

    parse_dates=['Date'])
          FBIDX =

pd.read_csv(,

    parse_dates=['Date'])
          NDX =

pd.read_csv(,

    parse_dates=['Date'])
          SO =

pd.read_csv(,

    parse_dates=['Date'])

show sample data

print(‘GSPC’)

print(GSPC.head())

print()

print(‘FBIDX’)

print(FBIDX.head())

print()

print(‘NDX’)

print(NDX.head())

print()

print(‘SO’)

print(SO.head())

In[10]:

data = dict(

Date = GSPC['Date'],
GSPC = GSPC['Adj Close'],
FBIDX = FBIDX['Adj Close'],
NDX = NDX['Adj Close'],
SO = SO['Adj Close'],

)

print(type(data[‘Date’][0]))

print(type(data[‘GSPC’][0]))

In[12]:

from bokeh.models import HoverTool

hover = HoverTool(

    tooltips = [
        ("Date", "$x"),
        ("Adj Close", "$y"),
    ]

)

ts_stocks = TimeSeries(data,

                  x = 'Date', y = ['GSPC', 'FBIDX',

‘NDX’, ‘SO’],

                  color = ['cadetblue', 'firebrick',

‘limegreen’, ‘hotpink’],

                  tools=['box_zoom', 'pan', 'save',

hover, ‘resize’, ‘reset’, ‘wheel_zoom’],

    title = 'Stock Time Series', 
                  ylabel = 'Stock Prices',

legend=True

)

show(ts_stocks)

Thanks in advance for any help.

Brad

  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 [email protected].

  To post to this group, send email to [email protected]

  To view this discussion on the web visit [](https://groups.google.com/a/continuum.io/d/msgid/bokeh/acde66b9-0f4b-4637-9d1c-8002624cd446%40continuum.io?utm_medium=email&utm_source=footer)      .

For more options, visit .


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

“https://ichart.yahoo.com/table.csv?s=^GSPC”“https://ichart.yahoo.com/table.csv?s=FBIDX”“https://ichart.yahoo.com/table.csv?s=^NDX”"https://ichart.yahoo.com/table.csv?s=SO"https://groups.google.com/a/continuum.io/d/msgid/bokeh/acde66b9-0f4b-4637-9d1c-8002624cd446%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

Sarah:

Thank you for the feedback. I see how not having all of the data present for the rendering of the chart is an issue. However, that information did not help me resolve the simple issue of a workable HoverTool. Could you help provide a workable solution for displaying the “Stock Name”, “Date” (from added SDate column), and the “Price” (Adj Close) as I attempted to do in the following example?

Note: I added the ‘SDate’ column as a string version of the ‘Date’ column for display purposes.

http://nbviewer.jupyter.org/github/behudson/jupyter-nb-public/blob/master/S%26P%20500%20Index%20to%20Southern%20Company%20-%20TimeSeries.ipynb

Charts is de signed
to be auto-magic for the simple cases.

I think you’re going to find "plotting " a lot easier for what you
want.

                  here's how to

create a line graph wit h plotting - note you can pass in a
data frame:

from bokeh.plotting
import figure

                                                          from

bokeh.models import ColumnDataSource

                    source = ColumnDataSource(data=data)

                    plot = figure()

                    plot.line(x='Date                        ',

y=’ ‘GSPC’’, source=source, line_width=3,
line_alpha=0.6, line_color…)

                  plot.line(x='Date', y=''                        FBIDX'', source=source, line_width=3,

line_alpha=0.6, line_color…)

                  plot.line(x='Date', y=''NDX                        '', source=source,

line_width=3, line_alpha=0.6, line_color…)

                    ...

Add a s many
plot.line as you need

                          Then finally when

you make your hover tool (just as shown in
your notebook) you’ll be able to ref erence the extra
columns because you’ll have put them in
source and
your hand-crafted source is all
hooked up to your lines.

                                  Some refs:

Best,

Bird

···

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/slider.py
https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/stocks.py
On 5/26/16 10:59 AM, Brad Hudson wrote:

Sarah:

      Thank you for the feedback. I see how not having all of the

data present for the rendering of the chart is an issue.
However, that information did not help me resolve the simple
issue of a workable HoverTool. Could you help provide a
workable solution for displaying the “Stock Name”, “Date”
(from added SDate column), and the “Price” (Adj Close) as I
attempted to do in the following example?

      Note: I added the 'SDate' column as a string version of the

‘Date’ column for display purposes.

http://nbviewer.jupyter.org/github/behudson/jupyter-nb-public/blob/master/S%26P%20500%20Index%20to%20Southern%20Company%20-%20TimeSeries.ipynb

  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 [email protected].

  To post to this group, send email to [email protected]

  To view this discussion on the web visit [](https://groups.google.com/a/continuum.io/d/msgid/bokeh/1591302f-ca1f-4860-9e2b-9f755d1a7803%40continuum.io?utm_medium=email&utm_source=footer)      .

For more options, visit .


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

https://groups.google.com/a/continuum.io/d/msgid/bokeh/1591302f-ca1f-4860-9e2b-9f755d1a7803%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

Hi,

I’d suggest the same as Sarah… Just for the record, you could still use “@x_values” on the tooltip to take the x values but since your x values are ts you’ll see the related number so you could use “SDate” instead for x (in this case it’d work anyway since your x axis would keep the same ordering and would work because TimeSeries is just a “smart-ish” wrapper around Line/Step charts.

Best

Fabio

···

On Thu, May 26, 2016 at 7:41 PM, Sarah Bird - Continuum [email protected] wrote:

Charts is de signed
to be auto-magic for the simple cases.

I think you’re going to find "plotting " a lot easier for what you
want.

                  here's how to

create a line graph wit h plotting - note you can pass in a
data frame:

from bokeh.plotting
import figure

                                                          from

bokeh.models import ColumnDataSource

                    source = ColumnDataSource(data=data)

                    plot = figure()

                    plot.line(x='Date                        ',

y=’

                    'GSPC'', source=source, line_width=3,

line_alpha=0.6, line_color…)

                  plot.line(x='Date', y=''

                    FBIDX'', source=source, line_width=3,

line_alpha=0.6, line_color…)

                  plot.line(x='Date', y=''NDX                        '', source=source,

line_width=3, line_alpha=0.6, line_color…)

                    ...

Add a s many
plot.line as you need

                          Then finally when

you make your hover tool (just as shown in
your notebook) you’ll be able to ref erence the extra
columns because you’ll have put them in
source and
your hand-crafted source is all
hooked up to your lines.

                                  Some refs:

                                    [https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/slider.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/slider.py)

                                      [https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/stocks.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/stocks.py)

Best,

Bird

On 5/26/16 10:59 AM, Brad Hudson wrote:

Sarah:

      Thank you for the feedback. I see how not having all of the

data present for the rendering of the chart is an issue.
However, that information did not help me resolve the simple
issue of a workable HoverTool. Could you help provide a
workable solution for displaying the “Stock Name”, “Date”
(from added SDate column), and the “Price” (Adj Close) as I
attempted to do in the following example?

      Note: I added the 'SDate' column as a string version of the

‘Date’ column for display purposes.

http://nbviewer.jupyter.org/github/behudson/jupyter-nb-public/blob/master/S%26P%20500%20Index%20to%20Southern%20Company%20-%20TimeSeries.ipynb

  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 [email protected].

  To post to this group, send email to [email protected]

  To view this discussion on the web visit [](https://groups.google.com/a/continuum.io/d/msgid/bokeh/1591302f-ca1f-4860-9e2b-9f755d1a7803%40continuum.io?utm_medium=email&utm_source=footer)[https://groups.google.com/a/continuum.io/d/msgid/bokeh/1591302f-ca1f-4860-9e2b-9f755d1a7803%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/1591302f-ca1f-4860-9e2b-9f755d1a7803%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://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](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 [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2c38cee8-e405-0ab2-ef63-903678026beb%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Fabio Pliger

Senior Software Engineer, Bokeh