import numpy as np
import pandas as pd

from collections import OrderedDict

from bokeh.plotting import *
from bokeh.objects import HoverTool

dataA = pd.read_csv('data4a.csv')
dataB = pd.read_csv('data4b.csv')
dataC = pd.read_csv('data4c.csv')
output_file("time.html", title="Time series example")

hold()

line(
    dataA['Iter'],                                       # x coordinates
    dataA['Energy'],                                  # y coordinates
    color='#A6CEE3',                                    # set a color for the line
    legend='data4A',                                      # attach a legend label
    # x_axis_type = "datetime",                           # NOTE: only needed on first
    tools="box_zoom,reset,previewsave,hover"   # NOTE: only needed on first
)

line(
    dataB['Iter'],                                       # x coordinates
    dataB['Energy'],                                  # y coordinates
    color='#B2DF8A',                                    # set a color for the line
    legend='data4B'                                      # attach a legend label
)

line(
    dataC['Iter'],                                       # x coordinates
    dataC['Energy'],                                  # y coordinates
    color='#33A02C',                                    # set a color for the line
    legend='data4C'                                      # attach a legend label
)
curplot().title = "Time series plot of Data"
# We want to add some fields for the hover tool to interrogate, but first we
# have to get ahold of the tool. We can use the 'select' method for that.
hover = curplot().select(dict(type=HoverTool))

# EXERCISE: add some new tooltip (name, value) pairs. Variables from the
# data source are available with a "@" prefix, e.g., "@x" will display the
# x value under the cursor. There are also some special known values that
# start with "$" symbol:
#   - $index     index of selected point in the data source
#   - $x, $y     "data" coordinates under cursor
#   - $sx, $sy   canvas coordinates under cursor
#   - $color     color data from data source, syntax: $color[options]:field_name
# NOTE: we use an OrderedDict to preserve the order in the displayed tooltip
hover.tooltips = OrderedDict([
    # add to this
    ("(x,y)", "(@x, @y)"),
    ("fill color", "$color[hex, swatch]:colors"),
])

# EXERCISE: style the plot, set a title, lighten the gridlines, etc.

grid().grid_line_alpha=0.3

show()  # open a browser