Dynamic Plot update on gridplot

Hi Bryan,

I have tried to update dynamic plots on gridplot object from the browser, but I can’t able to add a new plot on to column of the gridplot object, could you help me with this?

Code:

···

grid = gridplot([[p[select1.value][select2.value]]], toolbar_location=“left”, plot_width=1100, plot_height=300)

curdoc().add_root(grid)

def plot_update(attr, old, new):

global cts

grid.children[1].children.append(p[cts][new])

grid.update()

Thank you,

Vignesh M.

Hi,

There is not enough information below to speculate. I'd be happy to look at a small *complete* runnable script of what you have tried.

Bryan

···

On Apr 22, 2019, at 11:58 PM, [email protected] wrote:

Hi Bryan,

I have tried to update dynamic plots on gridplot object from the browser, but I can't able to add a new plot on to column of the gridplot object, could you help me with this?

Code:
######

grid = gridplot([[p[select1.value][select2.value]]], toolbar_location="left", plot_width=1100, plot_height=300)

curdoc().add_root(grid)

def plot_update(attr, old, new):
    global cts
    grid.children[1].children.append(p[cts][new])
    grid.update()

#####

Thank you,
Vignesh M.

--
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/c28f5dc4-8a78-47c4-82e0-9242eac61eb5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Sorry for the inconvenience,

Here I have attached the detailed code snippet below.

main.py

trade_names = [‘COPPER19APRFUT’, ‘GOLD19APRFUT’]

Plot Configuration

indicators = {‘RSI’: {‘y’: [‘RSI’], ‘plot’: ‘line’, ‘title’: ‘RSI’},

‘MACD’: {‘y’: [‘EMA12’, ‘EMA26’, ‘MACD’], ‘plot’: ‘macd’, ‘title’: ‘MACD’},

‘Heiken_Ashi’: {‘y’: [‘OPEN’, ‘CLOSE’, ‘HIGH’, ‘LOW’, ‘COLOR’], ‘plot’: ‘candlestick’, ‘title’: ‘Heiken_Ashi’}

}

Attached this Code Below

execfile(“sourcing_plots.py”)

@linear()

def update1(step):

pass

def update2(attr, old, new):

for key, value in indicators.iteritems():

curdoc().remove_root(p[old][key])

curdoc().add_root(p[new][ci])

def update3(attr, old, new):

global cts

print(grid)

#curdoc().add_root(p[cts][new])

grid.children[1].children.append(p[cts][new]) #<---- This line is not updating the plot on the browser

global cts

Select Box 1

trading_symbol = Select(value=trade_names[0], options=trade_names, name=‘symbol’)

Select Box 2

indicators_ = Select(value=indicator_names[0], options=indicator_names, name=‘indicators’)

cts = trading_symbol.value

ci = ‘Heiken_Ashi’

trading_symbol.on_change(‘value’, update2)

indicators_.on_change(‘value’, update3)

curdoc().add_root(trading_symbol)

curdoc().add_root(indicators_)

grid = gridplot([[p[trading_symbol.value][indicators_.value]]], toolbar_location=“left”, plot_width=1100, plot_height=300)

grid.name = “gridplot”

curdoc().add_root(grid)

#grid.children[1].children.append(p[trading_symbol.value][‘RSI’]) #<---- This line is working here, its updating the plot on the browser, but on function call this line is not working. At line 26

#curdoc().add_periodic_callback(update1, 100)

···

#####________________________________________________________________________________________________________________#####

sourcing_plots.py
Getting Figures From this File

for tn in trade_names:

i=0

for key, value in indicators.iteritems():

if value[‘plot’] == ‘line’:

p[tn][key] = figure(tools=“xpan,xwheel_zoom,xbox_zoom,reset,crosshair”, output_backend=‘canvas’, x_axis_type=None, y_axis_location=‘right’, toolbar_location=“left”, name=(tn+key))

if x_range != None:

p[tn][key].x_range = x_range

p[tn][key].sizing_mode = ‘scale_width’

p[tn][key].plot_height = height

p[tn][key].xaxis.formatter=DatetimeTickFormatter(days=[‘%b %d’])

line = p[tn][key].line(x=‘x’, y=str(value[‘y’][0]), color=“navy”, line_width=2, line_cap=‘round’, source=source[tn][key])

p[tn][key].add_tools(HoverTool(tooltips=[(“RSI”, “@”+str(value[‘y’][0])), (“DATETIME”, “@x{%F %T}”)], renderers=[line], formatters={‘x’: ‘datetime’}, mode=‘vline’))

p[tn][key].xgrid.visible = False

if value[‘plot’] == ‘macd’:

p[tn][key] = figure(plot_height=230, plot_width=800, tools=“xpan,xwheel_zoom,xbox_zoom,reset,crosshair”, y_axis_location=“right”, x_axis_type=None, toolbar_location=“left”, name=(tn+key))

if x_range != None:

p[tn][key].x_range = x_range

p[tn][key].sizing_mode = ‘scale_width’

p[tn][key].plot_height = height

p[tn][key].xaxis.formatter=DatetimeTickFormatter(days=[‘%b %d’])

p[tn][key].segment(x0=‘x’, y0=0, x1=‘x’, y1=str(value[‘y’][2]), line_width=2, color=‘grey’, alpha=0.5, source=source[tn][key])

p[tn][key].add_tools(HoverTool(tooltips=[(“MACD”, “@”+str(value[‘y’][2])), (“DATETIME”, “@x{%F %T}”)], formatters={‘x’: ‘datetime’}, mode=‘vline’))

if value[‘plot’] == ‘candlestick’:

p[tn][key] = figure(tools=“xpan,xwheel_zoom,xbox_zoom,reset,crosshair”, y_axis_location=“right”, x_axis_type=None, toolbar_location=“left”, name=(tn+key))

if x_range != None:

p[tn][key].x_range = x_range

p[tn][key].sizing_mode = ‘scale_width’

p[tn][key].plot_height = height

endtime = max(source[tn][key].data[‘x’]) + datetime.timedelta(minutes=3)

starttime = endtime - datetime.timedelta(minutes=45)

p[tn][key].x_range = Range1d(starttime, endtime)

p[tn][key].xaxis.formatter=DatetimeTickFormatter(days=[‘%b %d’])

p[tn][key].segment(x0=‘x’, y0=str(value[‘y’][3]), x1=‘x’, y1=str(value[‘y’][2]), line_width=2, color=‘black’, alpha=0.5, source=source[tn][key])

p[tn][key].segment(x0=‘x’, y0=str(value[‘y’][0]), x1=‘x’, y1=str(value[‘y’][1]), line_width=8, color=str(value[‘y’][4]), alpha=0.5, source=source[tn][key])

line = p[tn][key].line(x=‘x’, y=str(value[‘y’][0]), color=“grey”, line_width=2, line_cap=‘round’, alpha=0.3, source=source[tn][key])

p[tn][key].add_tools(HoverTool(tooltips=[(“OPEN”, “@”+str(value[‘y’][0])), (“CLOSE”, “@”+str(value[‘y’][1])), (“HIGH”, “@”+str(value[‘y’][2])), (“LOW”, “@”+str(value[‘y’][3])), (“DATETIME”, “@x{%F %T}”)], formatters={‘x’: ‘datetime’}, renderers=[line], mode=‘vline’))

On Tuesday, April 23, 2019 at 8:19:29 PM UTC+5:30, Bryan Van de Ven wrote:

Hi,

There is not enough information below to speculate. I’d be happy to look at a small complete runnable script of what you have tried.

Bryan

On Apr 22, 2019, at 11:58 PM, [email protected] wrote:

Hi Bryan,

I have tried to update dynamic plots on gridplot object from the browser, but I can’t able to add a new plot on to column of the gridplot object, could you help me with this?

Code:

grid = gridplot([[p[select1.value][select2.value]]], toolbar_location=“left”, plot_width=1100, plot_height=300)

curdoc().add_root(grid)

def plot_update(attr, old, new):

global cts
grid.children[1].children.append(p[cts][new])
grid.update()

Thank you,
Vignesh M.


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/c28f5dc4-8a78-47c4-82e0-9242eac61eb5%40continuum.io.

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

Hi,

This is really far too much complicated code. I was suggesting you craft a very minimal/simple example that illustrates just the issue with nothing extraneous or unrelated included. That said, I did still try to run it but was unsuccessful:

* it's python 2 only. I made a few changes to allow it to run on python 3. Please be aware that Bokeh will drop python 2 support entirely later this year

* Even after fixing up for python 3, it it was not complete. It is missing all the relevant imports. At this point I stopped trying.

If you can provide a *complete* *minimal* single script that is runnable as-is, without any modification, I will take a look.

Thanks,

Bryan

···

On Apr 23, 2019, at 7:49 AM, Bryan Van de Ven <[email protected]> wrote:

Hi,

There is not enough information below to speculate. I'd be happy to look at a small *complete* runnable script of what you have tried.

Bryan

On Apr 22, 2019, at 11:58 PM, [email protected] wrote:

Hi Bryan,

I have tried to update dynamic plots on gridplot object from the browser, but I can't able to add a new plot on to column of the gridplot object, could you help me with this?

Code:
######

grid = gridplot([[p[select1.value][select2.value]]], toolbar_location="left", plot_width=1100, plot_height=300)

curdoc().add_root(grid)

def plot_update(attr, old, new):
   global cts
   grid.children[1].children.append(p[cts][new])
   grid.update()

#####

Thank you,
Vignesh M.

--
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/c28f5dc4-8a78-47c4-82e0-9242eac61eb5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Thank you for your quick support, I will soon ping you back again with a small working piece of code about this issue.

Thank You,

Vignesh M.

···

On Friday, April 26, 2019 at 11:22:33 AM UTC+5:30, Bryan Van de Ven wrote:

Hi,

This is really far too much complicated code. I was suggesting you craft a very minimal/simple example that illustrates just the issue with nothing extraneous or unrelated included. That said, I did still try to run it but was unsuccessful:

  • it’s python 2 only. I made a few changes to allow it to run on python 3. Please be aware that Bokeh will drop python 2 support entirely later this year

  • Even after fixing up for python 3, it it was not complete. It is missing all the relevant imports. At this point I stopped trying.

If you can provide a complete minimal single script that is runnable as-is, without any modification, I will take a look.

Thanks,

Bryan

On Apr 23, 2019, at 7:49 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is not enough information below to speculate. I’d be happy to look at a small complete runnable script of what you have tried.

Bryan

On Apr 22, 2019, at 11:58 PM, [email protected] wrote:

Hi Bryan,

I have tried to update dynamic plots on gridplot object from the browser, but I can’t able to add a new plot on to column of the gridplot object, could you help me with this?

Code:

grid = gridplot([[p[select1.value][select2.value]]], toolbar_location=“left”, plot_width=1100, plot_height=300)

curdoc().add_root(grid)

def plot_update(attr, old, new):

global cts

grid.children[1].children.append(p[cts][new])

grid.update()

Thank you,
Vignesh M.


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/c28f5dc4-8a78-47c4-82e0-9242eac61eb5%40continuum.io.

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