update scatter plot x, y or both

I have a scatter plot for a data source and I also have selectors for the scatter X and Y.

So I just want to update the plot whenever the user selects a different X or Y for the scatter.

What is a good way to do this. I used to replace the whole plot, i.e. remove it from layout and make a new one,

but I don’t think that is a good way.

There must be some way to tell the figure that redraw with a different X, Y or both … right?

I am not changing the source, just the X and Y for the scatter.

I get the initial plot up fine, but not sure if I should update via a “patch” (and if so how do I make the patch)

or an update or something else like layout.set_selected()

I make the plot using

ScatterPlot = Figure()

ScatterPlot.scatter(…)

I am actually not sure if that is also best practice. The ScatterPlot.scatter() returns a glyph renderer, should I somehow be using that instead of the Figure?

I clearly need a better understanding of Figure, figure, Plot, and update & patch.

Any pointers to some examples and suggestions would be great.

Thanks greatly

  • john

I looked at the Stock ticker example in the Gallery and see that I can just follow that example.
That is, have a ColumnDataSource devoted to the scatter plot with keys X and Y

and just copy the underlying data into those columns needed.

Still, it would be nice if there were a way that did not involve copying data.

Will think more about that.

  • john
···

On Monday, October 9, 2017 at 4:13:43 PM UTC-4, John Muller wrote:

I have a scatter plot for a data source and I also have selectors for the scatter X and Y.

So I just want to update the plot whenever the user selects a different X or Y for the scatter.

What is a good way to do this. I used to replace the whole plot, i.e. remove it from layout and make a new one,

but I don’t think that is a good way.

There must be some way to tell the figure that redraw with a different X, Y or both … right?

I am not changing the source, just the X and Y for the scatter.

I get the initial plot up fine, but not sure if I should update via a “patch” (and if so how do I make the patch)

or an update or something else like layout.set_selected()

I make the plot using

ScatterPlot = Figure()

ScatterPlot.scatter(…)

I am actually not sure if that is also best practice. The ScatterPlot.scatter() returns a glyph renderer, should I somehow be using that instead of the Figure?

I clearly need a better understanding of Figure, figure, Plot, and update & patch.

Any pointers to some examples and suggestions would be great.

Thanks greatly

  • john

Hi John,

It sure is possible:

from bokeh.io import show, output_file
from bokeh.layouts import column
from bokeh.models import CustomJS
from bokeh.models.sources import ColumnDataSource
from bokeh.models.widgets import RadioGroup
from bokeh.plotting import figure

ds = ColumnDataSource(dict(x=[1, 2, 3],
                           y1=[1, 2, 3],
                           y2=[3, 2, 1]))

y_options = ['y1', 'y2']
y_active = 0
buttons = RadioGroup(labels=y_options, active=y_active)

f = figure()
circle = f.circle(x='x', y=y_options[y_active], source=ds)

buttons.js_on_change('active', CustomJS(args=dict(circle=circle),
                                        code="""
    // Must either replace "y" or just set "y.field" and call "circle.glyph.change.emit()"
    // I chose the first way
    circle.glyph.y = {field: cb_obj.labels[cb_obj.active]};
"""))

output_file('test.html')
show(column(f, buttons))

Regards,

Eugene

···

On Thursday, October 12, 2017 at 8:03:04 PM UTC+7, John Muller wrote:

I looked at the Stock ticker example in the Gallery and see that I can just follow that example.
That is, have a ColumnDataSource devoted to the scatter plot with keys X and Y

and just copy the underlying data into those columns needed.

Still, it would be nice if there were a way that did not involve copying data.

Will think more about that.

  • john

On Monday, October 9, 2017 at 4:13:43 PM UTC-4, John Muller wrote:

I have a scatter plot for a data source and I also have selectors for the scatter X and Y.

So I just want to update the plot whenever the user selects a different X or Y for the scatter.

What is a good way to do this. I used to replace the whole plot, i.e. remove it from layout and make a new one,

but I don’t think that is a good way.

There must be some way to tell the figure that redraw with a different X, Y or both … right?

I am not changing the source, just the X and Y for the scatter.

I get the initial plot up fine, but not sure if I should update via a “patch” (and if so how do I make the patch)

or an update or something else like layout.set_selected()

I make the plot using

ScatterPlot = Figure()

ScatterPlot.scatter(…)

I am actually not sure if that is also best practice. The ScatterPlot.scatter() returns a glyph renderer, should I somehow be using that instead of the Figure?

I clearly need a better understanding of Figure, figure, Plot, and update & patch.

Any pointers to some examples and suggestions would be great.

Thanks greatly

  • john