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