loading different source data for vbar

Hello,

I have another small issue with vbar’s

I am trying out the candlestick graph by calling in the data through json. that works fine.

I have two colors on vbars. one is red if the market close is lower than open. Other is blue if the market close is higher than open.

There are no issues in getting it to run correctly. the issue begins when i want to hover over the red and blue candles and display the source data.

My program is as below

-- coding: utf-8 --

“”"

Created on Thu Nov 30 10:39:21 2017

@author:

“”"

from bokeh.plotting import figure, output_file, show, ColumnDataSource

from bokeh.models import HoverTool

from math import pi

import pandas as pd

import datetime

import json

output_file(“toolbar.html”)

df = pd.read_json(’[{“datetime”: 1511568000000, “open”: “0.00215000”, “high”: “0.00215178”, “low”: “0.00214735”, “close”: “0.00214735”, “vwap”: “0.00215107”, “volume”: “5880.28136644”, “priceVolume”: “12.64889683”, “confirmed”: true}, {“datetime”: 1511481600000, “open”: “0.00212054”, “high”: “0.00239999”, “low”: “0.00210000”, “close”: “0.00215666”, “vwap”: “0.00213576”, “volume”: “90052.98859666”, “priceVolume”: “192.33157092”, “confirmed”: true}, {“datetime”: 1511395200000, “open”: “0.00251241”, “high”: “0.00258840”, “low”: “0.00212051”, “close”: “0.00252001”, “vwap”: “0.00247232”, “volume”: “37851.50333992”, “priceVolume”: “93.58102873”, “confirmed”: true}, {“datetime”: 1511308800000, “open”: “0.00230000”, “high”: “0.00255000”, “low”: “0.00222000”, “close”: “0.00255000”, “vwap”: “0.00240356”, “volume”: “51134.84974999”, “priceVolume”: “122.90567946”, “confirmed”: true}, {“datetime”: 1511222400000, “open”: “0.00235100”, “high”: “0.00252423”, “low”: “0.00230000”, “close”: “0.00252423”, “vwap”: “0.00235385”, “volume”: “20917.00000000”, “priceVolume”: “49.23548045”, “confirmed”: true}, {“datetime”: 1511136000000, “open”: “0.00250000”, “high”: “0.00260000”, “low”: “0.00235001”, “close”: “0.00235001”, “vwap”: “0.00250760”, “volume”: “11614.70126400”, “priceVolume”: “29.12502488”, “confirmed”: true}, {“datetime”: 1511049600000, “open”: “0.00261129”, “high”: “0.00262708”, “low”: “0.00240000”, “close”: “0.00260000”, “vwap”: “0.00254742”, “volume”: “126316.20198183”, “priceVolume”: “321.78041925”, “confirmed”: true}, {“datetime”: 1510963200000, “open”: “0.00252001”, “high”: “0.00284995”, “low”: “0.00248363”, “close”: “0.00263695”, “vwap”: “0.00264645”, “volume”: “111662.85992898”, “priceVolume”: “295.51017565”, “confirmed”: true}]’)

inc = df.close > df.open

dec = df.open > df.close

w = 126060*1000/5#

df = df.sort_values(by=[‘datetime’])

source1 = ColumnDataSource( data=dict( datetime = df[‘datetime’] ) )

source2 = ColumnDataSource( data=dict( datetime = [12, 14, 15] ) )

hover = HoverTool( tooltips=[(“df”,"@datetime")])

p = figure(x_axis_type=“datetime”, tools=[hover], plot_width=1000, title = “Candlestick”, toolbar_location=“above”)

p.xaxis.major_label_orientation = pi/4

p.grid.grid_line_alpha=0.3

p.segment(df.datetime, df.high, df.datetime, df.low, color=“black”)

p.vbar(df.datetime[inc], w, df.open[inc], df.close[inc], fill_color="#154360", line_color=“black”, source = source1)

p.vbar(df.datetime[dec], w, df.open[dec], df.close[dec], fill_color="#FF0000", line_color=“black”, source = source2)

show§

Ideally, I would have wanted to put source = source1 (instead of source2) in the second vbar and would have expected it to display correctly but it doesn’t. The blue bars disappears.

As of now source2 is just useless data just to make the red hover display something.

The warnings i get are

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\util\deprecation.py:34: BokehDeprecationWarning:

Supplying a user-defined data source AND iterable values to glyph methods is deprecated.

See https://github.com/bokeh/bokeh/issues/2056 for more information.

What is the right way to use it?

the second warning is

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\sources.py:137: BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘bottom’, 5), (‘datetime’, 8), (‘top’, 5), (‘x’, 5)

That is understandable since there are only 5 blue candles when 8 was passed (there are 3 red).

Would I have to manually split the json data and make separate source1 and source2 or is there an easier way to fix it?

Cheers.

hi,

I am able to find a solution to the first part of the the issue here regarding hover.

That works now.

I still wonder what to do remove the depreciation warning .

Thanks.

···

On Thursday, November 30, 2017 at 9:18:41 PM UTC+13, VT Sol wrote:

Hello,

I have another small issue with vbar’s

I am trying out the candlestick graph by calling in the data through json. that works fine.

I have two colors on vbars. one is red if the market close is lower than open. Other is blue if the market close is higher than open.

There are no issues in getting it to run correctly. the issue begins when i want to hover over the red and blue candles and display the source data.

My program is as below

-- coding: utf-8 --

“”"

Created on Thu Nov 30 10:39:21 2017

@author:

“”"

from bokeh.plotting import figure, output_file, show, ColumnDataSource

from bokeh.models import HoverTool

from math import pi

import pandas as pd

import datetime

import json

output_file(“toolbar.html”)

df = pd.read_json(’[{“datetime”: 1511568000000, “open”: “0.00215000”, “high”: “0.00215178”, “low”: “0.00214735”, “close”: “0.00214735”, “vwap”: “0.00215107”, “volume”: “5880.28136644”, “priceVolume”: “12.64889683”, “confirmed”: true}, {“datetime”: 1511481600000, “open”: “0.00212054”, “high”: “0.00239999”, “low”: “0.00210000”, “close”: “0.00215666”, “vwap”: “0.00213576”, “volume”: “90052.98859666”, “priceVolume”: “192.33157092”, “confirmed”: true}, {“datetime”: 1511395200000, “open”: “0.00251241”, “high”: “0.00258840”, “low”: “0.00212051”, “close”: “0.00252001”, “vwap”: “0.00247232”, “volume”: “37851.50333992”, “priceVolume”: “93.58102873”, “confirmed”: true}, {“datetime”: 1511308800000, “open”: “0.00230000”, “high”: “0.00255000”, “low”: “0.00222000”, “close”: “0.00255000”, “vwap”: “0.00240356”, “volume”: “51134.84974999”, “priceVolume”: “122.90567946”, “confirmed”: true}, {“datetime”: 1511222400000, “open”: “0.00235100”, “high”: “0.00252423”, “low”: “0.00230000”, “close”: “0.00252423”, “vwap”: “0.00235385”, “volume”: “20917.00000000”, “priceVolume”: “49.23548045”, “confirmed”: true}, {“datetime”: 1511136000000, “open”: “0.00250000”, “high”: “0.00260000”, “low”: “0.00235001”, “close”: “0.00235001”, “vwap”: “0.00250760”, “volume”: “11614.70126400”, “priceVolume”: “29.12502488”, “confirmed”: true}, {“datetime”: 1511049600000, “open”: “0.00261129”, “high”: “0.00262708”, “low”: “0.00240000”, “close”: “0.00260000”, “vwap”: “0.00254742”, “volume”: “126316.20198183”, “priceVolume”: “321.78041925”, “confirmed”: true}, {“datetime”: 1510963200000, “open”: “0.00252001”, “high”: “0.00284995”, “low”: “0.00248363”, “close”: “0.00263695”, “vwap”: “0.00264645”, “volume”: “111662.85992898”, “priceVolume”: “295.51017565”, “confirmed”: true}]’)

inc = df.close > df.open

dec = df.open > df.close

w = 126060*1000/5#

df = df.sort_values(by=[‘datetime’])

source1 = ColumnDataSource( data=dict( datetime = df[‘datetime’] ) )

source2 = ColumnDataSource( data=dict( datetime = [12, 14, 15] ) )

hover = HoverTool( tooltips=[(“df”,"@datetime")])

p = figure(x_axis_type=“datetime”, tools=[hover], plot_width=1000, title = “Candlestick”, toolbar_location=“above”)

p.xaxis.major_label_orientation = pi/4

p.grid.grid_line_alpha=0.3

p.segment(df.datetime, df.high, df.datetime, df.low, color=“black”)

p.vbar(df.datetime[inc], w, df.open[inc], df.close[inc], fill_color="#154360", line_color=“black”, source = source1)

p.vbar(df.datetime[dec], w, df.open[dec], df.close[dec], fill_color="#FF0000", line_color=“black”, source = source2)

show§

Ideally, I would have wanted to put source = source1 (instead of source2) in the second vbar and would have expected it to display correctly but it doesn’t. The blue bars disappears.

As of now source2 is just useless data just to make the red hover display something.

The warnings i get are

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\util\deprecation.py:34: BokehDeprecationWarning:

Supplying a user-defined data source AND iterable values to glyph methods is deprecated.

See https://github.com/bokeh/bokeh/issues/2056 for more information.

What is the right way to use it?

the second warning is

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\sources.py:137: BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘bottom’, 5), (‘datetime’, 8), (‘top’, 5), (‘x’, 5)

That is understandable since there are only 5 blue candles when 8 was passed (there are 3 red).

Would I have to manually split the json data and make separate source1 and source2 or is there an easier way to fix it?

Cheers.

Hi,

Just as the warning says, you pass data to “p.vbar” both as iterables (df.datetime[inc], df.open[inc] etc.) and as a data source (source = source1). You should create all columns that you need in the data source, and pass only that data source to the glyph method.

You can look how to do it in this example: https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors

Regards,

Eugene

···

On Friday, December 1, 2017 at 6:52:12 AM UTC+7, VT Sol wrote:

hi,

I am able to find a solution to the first part of the the issue here regarding hover.

http://perfspy.blogspot.co.nz/2017/03/candlestick-chart-using-boken-without.html

That works now.

I still wonder what to do remove the depreciation warning .

Thanks.

On Thursday, November 30, 2017 at 9:18:41 PM UTC+13, VT Sol wrote:

Hello,

I have another small issue with vbar’s

I am trying out the candlestick graph by calling in the data through json. that works fine.

I have two colors on vbars. one is red if the market close is lower than open. Other is blue if the market close is higher than open.

There are no issues in getting it to run correctly. the issue begins when i want to hover over the red and blue candles and display the source data.

My program is as below

-- coding: utf-8 --

“”"

Created on Thu Nov 30 10:39:21 2017

@author:

“”"

from bokeh.plotting import figure, output_file, show, ColumnDataSource

from bokeh.models import HoverTool

from math import pi

import pandas as pd

import datetime

import json

output_file(“toolbar.html”)

df = pd.read_json(’[{“datetime”: 1511568000000, “open”: “0.00215000”, “high”: “0.00215178”, “low”: “0.00214735”, “close”: “0.00214735”, “vwap”: “0.00215107”, “volume”: “5880.28136644”, “priceVolume”: “12.64889683”, “confirmed”: true}, {“datetime”: 1511481600000, “open”: “0.00212054”, “high”: “0.00239999”, “low”: “0.00210000”, “close”: “0.00215666”, “vwap”: “0.00213576”, “volume”: “90052.98859666”, “priceVolume”: “192.33157092”, “confirmed”: true}, {“datetime”: 1511395200000, “open”: “0.00251241”, “high”: “0.00258840”, “low”: “0.00212051”, “close”: “0.00252001”, “vwap”: “0.00247232”, “volume”: “37851.50333992”, “priceVolume”: “93.58102873”, “confirmed”: true}, {“datetime”: 1511308800000, “open”: “0.00230000”, “high”: “0.00255000”, “low”: “0.00222000”, “close”: “0.00255000”, “vwap”: “0.00240356”, “volume”: “51134.84974999”, “priceVolume”: “122.90567946”, “confirmed”: true}, {“datetime”: 1511222400000, “open”: “0.00235100”, “high”: “0.00252423”, “low”: “0.00230000”, “close”: “0.00252423”, “vwap”: “0.00235385”, “volume”: “20917.00000000”, “priceVolume”: “49.23548045”, “confirmed”: true}, {“datetime”: 1511136000000, “open”: “0.00250000”, “high”: “0.00260000”, “low”: “0.00235001”, “close”: “0.00235001”, “vwap”: “0.00250760”, “volume”: “11614.70126400”, “priceVolume”: “29.12502488”, “confirmed”: true}, {“datetime”: 1511049600000, “open”: “0.00261129”, “high”: “0.00262708”, “low”: “0.00240000”, “close”: “0.00260000”, “vwap”: “0.00254742”, “volume”: “126316.20198183”, “priceVolume”: “321.78041925”, “confirmed”: true}, {“datetime”: 1510963200000, “open”: “0.00252001”, “high”: “0.00284995”, “low”: “0.00248363”, “close”: “0.00263695”, “vwap”: “0.00264645”, “volume”: “111662.85992898”, “priceVolume”: “295.51017565”, “confirmed”: true}]’)

inc = df.close > df.open

dec = df.open > df.close

w = 126060*1000/5#

df = df.sort_values(by=[‘datetime’])

source1 = ColumnDataSource( data=dict( datetime = df[‘datetime’] ) )

source2 = ColumnDataSource( data=dict( datetime = [12, 14, 15] ) )

hover = HoverTool( tooltips=[(“df”,"@datetime")])

p = figure(x_axis_type=“datetime”, tools=[hover], plot_width=1000, title = “Candlestick”, toolbar_location=“above”)

p.xaxis.major_label_orientation = pi/4

p.grid.grid_line_alpha=0.3

p.segment(df.datetime, df.high, df.datetime, df.low, color=“black”)

p.vbar(df.datetime[inc], w, df.open[inc], df.close[inc], fill_color="#154360", line_color=“black”, source = source1)

p.vbar(df.datetime[dec], w, df.open[dec], df.close[dec], fill_color="#FF0000", line_color=“black”, source = source2)

show§

Ideally, I would have wanted to put source = source1 (instead of source2) in the second vbar and would have expected it to display correctly but it doesn’t. The blue bars disappears.

As of now source2 is just useless data just to make the red hover display something.

The warnings i get are

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\util\deprecation.py:34: BokehDeprecationWarning:

Supplying a user-defined data source AND iterable values to glyph methods is deprecated.

See https://github.com/bokeh/bokeh/issues/2056 for more information.

What is the right way to use it?

the second warning is

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\sources.py:137: BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘bottom’, 5), (‘datetime’, 8), (‘top’, 5), (‘x’, 5)

That is understandable since there are only 5 blue candles when 8 was passed (there are 3 red).

Would I have to manually split the json data and make separate source1 and source2 or is there an easier way to fix it?

Cheers.

Got it, thank you!

···

On Fri, Dec 1, 2017 at 7:12 PM, Eugene Pakhomov [email protected] wrote:

Hi,

Just as the warning says, you pass data to “p.vbar” both as iterables (df.datetime[inc], df.open[inc] etc.) and as a data source (source = source1). You should create all columns that you need in the data source, and pass only that data source to the glyph method.

You can look how to do it in this example: https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors

Regards,

Eugene

On Friday, December 1, 2017 at 6:52:12 AM UTC+7, VT Sol wrote:

hi,

I am able to find a solution to the first part of the the issue here regarding hover.

http://perfspy.blogspot.co.nz/2017/03/candlestick-chart-using-boken-without.html

That works now.

I still wonder what to do remove the depreciation warning .

Thanks.

On Thursday, November 30, 2017 at 9:18:41 PM UTC+13, VT Sol wrote:

Hello,

I have another small issue with vbar’s

I am trying out the candlestick graph by calling in the data through json. that works fine.

I have two colors on vbars. one is red if the market close is lower than open. Other is blue if the market close is higher than open.

There are no issues in getting it to run correctly. the issue begins when i want to hover over the red and blue candles and display the source data.

My program is as below

-- coding: utf-8 --

“”"

Created on Thu Nov 30 10:39:21 2017

@author:

“”"

from bokeh.plotting import figure, output_file, show, ColumnDataSource

from bokeh.models import HoverTool

from math import pi

import pandas as pd

import datetime

import json

output_file(“toolbar.html”)

df = pd.read_json(’[{“datetime”: 1511568000000, “open”: “0.00215000”, “high”: “0.00215178”, “low”: “0.00214735”, “close”: “0.00214735”, “vwap”: “0.00215107”, “volume”: “5880.28136644”, “priceVolume”: “12.64889683”, “confirmed”: true}, {“datetime”: 1511481600000, “open”: “0.00212054”, “high”: “0.00239999”, “low”: “0.00210000”, “close”: “0.00215666”, “vwap”: “0.00213576”, “volume”: “90052.98859666”, “priceVolume”: “192.33157092”, “confirmed”: true}, {“datetime”: 1511395200000, “open”: “0.00251241”, “high”: “0.00258840”, “low”: “0.00212051”, “close”: “0.00252001”, “vwap”: “0.00247232”, “volume”: “37851.50333992”, “priceVolume”: “93.58102873”, “confirmed”: true}, {“datetime”: 1511308800000, “open”: “0.00230000”, “high”: “0.00255000”, “low”: “0.00222000”, “close”: “0.00255000”, “vwap”: “0.00240356”, “volume”: “51134.84974999”, “priceVolume”: “122.90567946”, “confirmed”: true}, {“datetime”: 1511222400000, “open”: “0.00235100”, “high”: “0.00252423”, “low”: “0.00230000”, “close”: “0.00252423”, “vwap”: “0.00235385”, “volume”: “20917.00000000”, “priceVolume”: “49.23548045”, “confirmed”: true}, {“datetime”: 1511136000000, “open”: “0.00250000”, “high”: “0.00260000”, “low”: “0.00235001”, “close”: “0.00235001”, “vwap”: “0.00250760”, “volume”: “11614.70126400”, “priceVolume”: “29.12502488”, “confirmed”: true}, {“datetime”: 1511049600000, “open”: “0.00261129”, “high”: “0.00262708”, “low”: “0.00240000”, “close”: “0.00260000”, “vwap”: “0.00254742”, “volume”: “126316.20198183”, “priceVolume”: “321.78041925”, “confirmed”: true}, {“datetime”: 1510963200000, “open”: “0.00252001”, “high”: “0.00284995”, “low”: “0.00248363”, “close”: “0.00263695”, “vwap”: “0.00264645”, “volume”: “111662.85992898”, “priceVolume”: “295.51017565”, “confirmed”: true}]’)

inc = df.close > df.open

dec = df.open > df.close

w = 126060*1000/5#

df = df.sort_values(by=[‘datetime’])

source1 = ColumnDataSource( data=dict( datetime = df[‘datetime’] ) )

source2 = ColumnDataSource( data=dict( datetime = [12, 14, 15] ) )

hover = HoverTool( tooltips=[(“df”,"@datetime")])

p = figure(x_axis_type=“datetime”, tools=[hover], plot_width=1000, title = “Candlestick”, toolbar_location=“above”)

p.xaxis.major_label_orientation = pi/4

p.grid.grid_line_alpha=0.3

p.segment(df.datetime, df.high, df.datetime, df.low, color=“black”)

p.vbar(df.datetime[inc], w, df.open[inc], df.close[inc], fill_color="#154360", line_color=“black”, source = source1)

p.vbar(df.datetime[dec], w, df.open[dec], df.close[dec], fill_color="#FF0000", line_color=“black”, source = source2)

show§

Ideally, I would have wanted to put source = source1 (instead of source2) in the second vbar and would have expected it to display correctly but it doesn’t. The blue bars disappears.

As of now source2 is just useless data just to make the red hover display something.

The warnings i get are

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\util\deprecation.py:34: BokehDeprecationWarning:

Supplying a user-defined data source AND iterable values to glyph methods is deprecated.

See https://github.com/bokeh/bokeh/issues/2056 for more information.

What is the right way to use it?

the second warning is

C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\sources.py:137: BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘bottom’, 5), (‘datetime’, 8), (‘top’, 5), (‘x’, 5)

That is understandable since there are only 5 blue candles when 8 was passed (there are 3 red).

Would I have to manually split the json data and make separate source1 and source2 or is there an easier way to fix it?

Cheers.

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/7f5b6153-c85b-428d-913b-1a8d916007c3%40continuum.io.

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