Help needed with changing bokeh Glyph x and y fields

Hello,

After trying multiple options I decided to ask for experts help in the following issue:

In my project I have a scatter plot (Figure.circle) that is connected to a ColumnDataSource and two of its fields.

In my bokeh server applicationI must change based on a widgets.Select the two columns that the circle glyph is plotting.

Initially I create the GlyphRenderer with:

renderer = fig.circle( x_field, y_field, source)

This works fine and initial plot is showed.

However when I must change the “axis” I use the Select and within on_change of Select if do:

renderer.glyph.x = new_x_field

renderer.glyph.y = new_y_field

Certainly the ColumnDataSource has all required fields/data however **nothing changes visually **when above code is run.

I kindly as for your help,

Thank you in advance!

I think that you should use a list with variable instead of a variable: [new_x_field] instead of new_x_field

I learned that it is always better to update all field at once with “stream”. Could you try this?

from bokeh.models import ColumnDataSource

from bokeh.plotting import *

data_source_dictionary = dict(x = , y = )

data_source = ColumnDataSource(data_source_dictionary)

fig = Figure()

renderer = fig.circle( x = ‘x’, y = ‘y’, source = data_source)

new_source_data = dict(x = [new_x], y = [new_y])

data_source.stream(new_source_data)

Alternative way is that you update the data separately but it is not recommended:

renderer.data_source.data[‘x’] = [new_x]

renderer.data_source.data[‘y’] = [new_y]

···

On Thursday, January 12, 2017 at 11:01:42 AM UTC+1, [email protected] wrote:

Hello,

After trying multiple options I decided to ask for experts help in the following issue:

In my project I have a scatter plot (Figure.circle) that is connected to a ColumnDataSource and two of its fields.

In my bokeh server applicationI must change based on a widgets.Select the two columns that the circle glyph is plotting.

Initially I create the GlyphRenderer with:

renderer = fig.circle( x_field, y_field, source)

This works fine and initial plot is showed.

However when I must change the “axis” I use the Select and within on_change of Select if do:

renderer.glyph.x = new_x_field

renderer.glyph.y = new_y_field

Certainly the ColumnDataSource has all required fields/data however **nothing changes visually **when above code is run.

I kindly as for your help,

Thank you in advance!

Unfortunately, the necessary plumbing to have glyphs responds to changes of field names, in particular, is not yet hooked up. For now your best option is to update data sources, which is a well established technique. I'd encourage you to file a feature request issue, since it would be valuable in cases were you don't want to re-send data.

For completeness, here is a small example that does what you describe, in this other way:

    from bokeh.io import curdoc
    from bokeh.layouts import column
    from bokeh.models import Button, ColumnDataSource
    from bokeh.plotting import figure

    x = [1,2,3,4,5]
    y0 = [1,4,9,16,25]
    y1 = [5,4,3,2,1]

    source = ColumnDataSource(data=dict(x=x, y=y0))

    plot = figure()
    plot.line('x', 'y', source=source)

    def callback():
        source.data.update(x=x, y=y1)

    button = Button()
    button.on_click(callback)

    curdoc().add_root(column(button, plot))

Thanks,

Bryan

···

On Jan 12, 2017, at 4:29 PM, [email protected] wrote:

I think that you should use a list with variable instead of a variable: [new_x_field] instead of new_x_field

I learned that it is always better to update all field at once with "stream". Could you try this?

from bokeh.models import ColumnDataSource
from bokeh.plotting import *

data_source_dictionary = dict(x = , y = )
data_source = ColumnDataSource(data_source_dictionary)
fig = Figure()
renderer = fig.circle( x = 'x', y = 'y', source = data_source)

new_source_data = dict(x = [new_x], y = [new_y])
data_source.stream(new_source_data)

Alternative way is that you update the data separately but it is not recommended:

renderer.data_source.data['x'] = [new_x]
renderer.data_source.data['y'] = [new_y]

On Thursday, January 12, 2017 at 11:01:42 AM UTC+1, [email protected] wrote:
Hello,

After trying multiple options I decided to ask for experts help in the following issue:

In my project I have a scatter plot (Figure.circle) that is connected to a ColumnDataSource and two of its fields.
In my bokeh server applicationI must change based on a widgets.Select the two columns that the circle glyph is plotting.
Initially I create the GlyphRenderer with:

renderer = fig.circle( x_field, y_field, source)

This works fine and initial plot is showed.

However when I must change the "axis" I use the Select and within on_change of Select if do:

renderer.glyph.x = new_x_field
renderer.glyph.y = new_y_field

Certainly the ColumnDataSource has all required fields/data however nothing changes visually when above code is run.

I kindly as for your help,

Thank you in advance!

--
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/c9addd7d-e83e-4e63-b441-9f29d648f39d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.