I have a price chart that displays closing price over time (blue), a moving average (red), and the upper and lower bounds of a Bollinger band (black). It looks something like this:

Ignore for now how ugly it looks. What I want to do is add a semi-transparent grey area between the two black lines. I’m not sure what Glyph to use for this. At first, it seemed like Segment would work, since it takes two sets of x and y points, but it doesn’t behave how I expected - it created a bunch of vertical lines at each data point, without any transparency. I’m looking to shade the entire area below the upper boundary and above the lower boundary, instead.

Is there an object I can use that will do this? Or is there a different method that would work better?

You need to use a use the "patch" glyph, there is an example in "examples/plotting/file/glyphs.py". Basically you just supply all the point of the a polygon. So for two bands like this, reverse the top set of points, and then append it to the bottom set, and use those at the points for the patch glyph.

I have a price chart that displays closing price over time (blue), a moving average (red), and the upper and lower bounds of a Bollinger band (black). It looks something like this:

Ignore for now how ugly it looks. What I want to do is add a semi-transparent grey area between the two black lines. I'm not sure what Glyph to use for this. At first, it seemed like Segment would work, since it takes two sets of x and y points, but it doesn't behave how I expected - it created a bunch of vertical lines at each data point, without any transparency. I'm looking to shade the entire area below the upper boundary and above the lower boundary, instead.

Is there an object I can use that will do this? Or is there a different method that would work better?

Ohh, so that’s where the Glyphs examples went! Okay, this helps.

So just to document what I’m doing: for Patch, the set of x is the dates index of the data and the set of y is, in semi-psuedocode, lowerband.extend(upperband.reverse()). Correct?

The Pandas TimeSeries structure associates the data points with a date (e.g. 2013-11-22 519.80). If I reorder the structure, the order will change, but the points will keep their associated date index. Will this display differently on a plot, or does the fact that each stock price (y) is associated with a date (x) mean that it won’t look any different?

···

On Thu, Nov 28, 2013 at 1:32 AM, Bryan Van de Ven [email protected] wrote:

You need to use a use the “patch” glyph, there is an example in “examples/plotting/file/glyphs.py”. Basically you just supply all the point of the a polygon. So for two bands like this, reverse the top set of points, and then append it to the bottom set, and use those at the points for the patch glyph.

I have a price chart that displays closing price over time (blue), a moving average (red), and the upper and lower bounds of a Bollinger band (black). It looks something like this:

Ignore for now how ugly it looks. What I want to do is add a semi-transparent grey area between the two black lines. I’m not sure what Glyph to use for this. At first, it seemed like Segment would work, since it takes two sets of x and y points, but it doesn’t behave how I expected - it created a bunch of vertical lines at each data point, without any transparency. I’m looking to shade the entire area below the upper boundary and above the lower boundary, instead.

Is there an object I can use that will do this? Or is there a different method that would work better?

–

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].

You need to append a reversed set of x values too (x and y for patch should be the same length). I would just make a copy of the date series for the patch glyph.

···

On Thu, Nov 28, 2013 at 1:32 AM, Bryan Van de Ven [email protected] wrote:

You need to use a use the “patch” glyph, there is an example in “examples/plotting/file/glyphs.py”. Basically you just supply all the point of the a polygon. So for two bands like this, reverse the top set of points, and then append it to the bottom set, and use those at the points for the patch glyph.

I have a price chart that displays closing price over time (blue), a moving average (red), and the upper and lower bounds of a Bollinger band (black). It looks something like this:

Ignore for now how ugly it looks. What I want to do is add a semi-transparent grey area between the two black lines. I’m not sure what Glyph to use for this. At first, it seemed like Segment would work, since it takes two sets of x and y points, but it doesn’t behave how I expected - it created a bunch of vertical lines at each data point, without any transparency. I’m looking to shade the entire area below the upper boundary and above the lower boundary, instead.

Is there an object I can use that will do this? Or is there a different method that would work better?

–

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].

The plot is almost correct now, but the dates show up as NaN for some reason. This might be because I changed the x and y points of the basic stock data to just a numpy array of the price and date values instead of a pandas data structure, to make it simpler. I’ll have to change both the raw data’s date series as well as the band’s date series to a Pandas DatetimeIndex, by doing something like this:

pandas.to_datetime(banddates)

where banddates is the Numpy array version of the raw dates with a reversed version of itself appended to it. So, it’s converting a Numpy array to a DatetimeIndex - and that seems to work!

Everything displays correctly now (as far as I can see). This wasn’t immediately obvious, and I know others might want to add bands to their stock data, so here’s a snippet of how I got the band to display correctly and how I got the right data formats:

from bokeh.plotting import *

import datetime

import pandas

import pandas.io.data as web

start = datetime.date(2012, 1, 1)

end = datetime.date.today()

data = web.DataReader(‘AAPL’, ‘google’, start, end)

close = data[‘Close’].values # Type: Numpy array

dates = data.index.values # Type: Numpy array

Plotting raw stock data.

x = data.index # Type: Pandas DatetimeIndex

y = close # Type: Numpy array

line(x, y, color=‘blue’, x_axis_type=‘datetime’) # DatetimeIndex vs. Numpy array

patch(pandas.to_datetime(banddates), bandprice, color=‘#A6CEE3’, fill_alpha=0.3, x_axis_type=‘datetime’) # DatetimeIndex vs. Numpy array

There might be a simpler way of explaining this, but this is the best I can do. I’m not too great at documentation, so if anyone needs clarification, I implore you to ask!

···

Anyway, it finally works. Thanks, Bryan! I did also find a bug of sorts: resizing a graph gets kinda sketchy if you move the cursor too quickly. I’m using Google Chrome, and if you move too fast, the resizing “stops”. It’s kinda hard to explain, so try turning the resize function on, holding onto the corner of the graph, and move the cursor really quickly to the right. You’ll see what I mean.

Also, any advice for adding functionality or making this look nicer would be greatly appreciated!

On Thursday, November 28, 2013 2:14:43 PM UTC-5, Bryan Van de ven wrote:

You need to append a reversed set of x values too (x and y for patch should be the same length). I would just make a copy of the date series for the patch glyph.

Ohh, so that’s where the Glyphs examples went! Okay, this helps.

So just to document what I’m doing: for Patch, the set of x is the dates index of the data and the set of y is, in semi-psuedocode, lowerband.extend(upperband.reverse()). Correct?

The Pandas TimeSeries structure associates the data points with a date (e.g. 2013-11-22 519.80). If I reorder the structure, the order will change, but the points will keep their associated date index. Will this display differently on a plot, or does the fact that each stock price (y) is associated with a date (x) mean that it won’t look any different?

On Thu, Nov 28, 2013 at 1:32 AM, Bryan Van de Ven [email protected] wrote:

You need to use a use the “patch” glyph, there is an example in “examples/plotting/file/glyphs.py”. Basically you just supply all the point of the a polygon. So for two bands like this, reverse the top set of points, and then append it to the bottom set, and use those at the points for the patch glyph.

I have a price chart that displays closing price over time (blue), a moving average (red), and the upper and lower bounds of a Bollinger band (black). It looks something like this:

Ignore for now how ugly it looks. What I want to do is add a semi-transparent grey area between the two black lines. I’m not sure what Glyph to use for this. At first, it seemed like Segment would work, since it takes two sets of x and y points, but it doesn’t behave how I expected - it created a bunch of vertical lines at each data point, without any transparency. I’m looking to shade the entire area below the upper boundary and above the lower boundary, instead.

Is there an object I can use that will do this? Or is there a different method that would work better?

–

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].