In [9]:
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import NumeralTickFormatter
from bokeh.models import FixedTicker
import math
from IPython.display import Image

In [10]:
output_notebook()


Loading BokehJS ...

Showing the before/after as static images below since github does not show bokeh's output:


In [22]:
Image("./images/before.png")


Out[22]:

In [23]:
Image("./images/after.png")


Out[23]:

In [3]:
a = [1, 2, 3, 4, 5, 6]
b = [2, 5, 9, 1, 2, 4]

In [24]:
p = figure(plot_height = 300, plot_width = 500, title=' , Volume')

p.line(a, b, legend='something', color='green', line_width=2)
p.left[0].formatter.use_scientific = False

p.xaxis.ticker = FixedTicker(ticks=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
p.yaxis[0].formatter = NumeralTickFormatter(format="0,0")
p.legend.background_fill_alpha = 0.1
show(p)



In [25]:
def step_line(x, y):
    """
    ingest two lists
    set offsets such that the data can be used
    to generate a step-line plot.
    
    Steps are thus:
        * for x's, repeat all but the first.
        * for y's, double up each occurance except the last
    
    Example:
        Before:
            a = [1, 2, 3, 4, 5]
            b = [2, 5, 9, 1, 2]
        After:
            a = [1, 2, 2, 3, 3, 4, 4, 5, 5]
            b = [2, 2, 5, 5, 9, 9, 1, 1, 2]
    """
    x1 = []
    y1 = []
    
    for idx in (range(len(x)*2-1)):
        if idx == 0:
            print(idx)
            x1.append(x[idx])
            y1.append(y[idx])
        else:
            #print('ceil is: ' + str(math.ceil(idx/2)))
            x1.append(x[math.ceil(idx/2)])
            y1.append(y[math.floor(idx/2)])
    return x1, y1

In [26]:
one, two = step_line(a, b)


0

In [27]:
p = figure(plot_height = 300, plot_width = 500, title=' , Volume')

p.line(one, two, legend='something', color='green', line_width=2)
p.left[0].formatter.use_scientific = False

p.xaxis.ticker = FixedTicker(ticks=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
p.yaxis[0].formatter = NumeralTickFormatter(format="0,0")
p.legend.background_fill_alpha = 0.1
show(p)



In [ ]: