updating images?

Is there a way to get the image plot to update when I change the data?

Everything I’ve tried so far, (change the image data in the plot, change the plot itself) doesn’t work and none of the examples show a changing image data.

Can you describe what you have tried more fully? This is assuming you are using the bokeh-server, correct?

Thanks,

Bryan

···

On Dec 2, 2014, at 10:21 AM, [email protected] wrote:

Is there a way to get the image plot to update when I change the data?

Everything I've tried so far, (change the image data in the plot, change the plot itself) doesn't work and none of the examples show a changing image data.

--
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/69035a3a-e53d-4ce4-8813-c2dff7869175%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Yes, I’m using bokeh-server:

The two ways that I’ve tried are:

self.image = image([some_image], …)

then, when the image changes, do

self.image = image([new_image], …)

The other way, I’ve done it is:

self.image_data = [image_generation_function()]

self.image = image(self.image_data, …)

then, when the image changes do

self.image_data = [image_generation_function()]

hoping that the change in the image data will be detected by the image plot.

Neither seems to work for me.

Also, I notice that other plots have a source data object that you can change and it will automatically change that in the plot. I didn’t see that in the examples for images, and I don’t think I’ve tried it yet (or I may have and I just don’t remember it not working).

···

On Tuesday, December 2, 2014 9:28:11 AM UTC-7, Bryan Van de ven wrote:

Can you describe what you have tried more fully? This is assuming you are using the bokeh-server, correct?

Thanks,

Bryan

On Dec 2, 2014, at 10:21 AM, [email protected] wrote:

Is there a way to get the image plot to update when I change the data?

Everything I’ve tried so far, (change the image data in the plot, change the plot itself) doesn’t work and none of the examples show a changing image data.


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/69035a3a-e53d-4ce4-8813-c2dff7869175%40continuum.io.

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

A related question, how do I change attributes on an existing plot, because I don’t understand the Instance(Plot) mechanisms in bokeh-server scripts.

If I do:

obj.image = rect('x', 'y', tools=toolset, source=obj.image_source,

                   plot_width=300, plot_height=300, color='v',

                   width=1, height=1)

Then I want to change the width and height,

obj.image.width = some_value

doesn’t do anything, because it doesn’t seem to be an attribute of the plot.

The bokeh-server mechanisms seem a bit mysterious to me, and I think this is the trouble I am running into trying to decipher how to change an existing plot.

···

On Tuesday, December 2, 2014 11:19:24 AM UTC-7, Jon Woodring wrote:

Yes, I’m using bokeh-server:

The two ways that I’ve tried are:

self.image = image([some_image], …)

then, when the image changes, do

self.image = image([new_image], …)

The other way, I’ve done it is:

self.image_data = [image_generation_function()]

self.image = image(self.image_data, …)

then, when the image changes do

self.image_data = [image_generation_function()]

hoping that the change in the image data will be detected by the image plot.

Neither seems to work for me.

Also, I notice that other plots have a source data object that you can change and it will automatically change that in the plot. I didn’t see that in the examples for images, and I don’t think I’ve tried it yet (or I may have and I just don’t remember it not working).

On Tuesday, December 2, 2014 9:28:11 AM UTC-7, Bryan Van de ven wrote:

Can you describe what you have tried more fully? This is assuming you are using the bokeh-server, correct?

Thanks,

Bryan

On Dec 2, 2014, at 10:21 AM, [email protected] wrote:

Is there a way to get the image plot to update when I change the data?

Everything I’ve tried so far, (change the image data in the plot, change the plot itself) doesn’t work and none of the examples show a changing image data.


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/69035a3a-e53d-4ce4-8813-c2dff7869175%40continuum.io.

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

One final confusion with how classes work in bokeh-server is that this doesn’t work:

class CosmicEmu(HBox):

…some stuff

some additional class initializers

CosmicEmu.names = [‘omega_b’, ‘omega_m’, ‘n_s’, ‘h’, ‘w’, ‘sigma_8’, ‘z’]

for i in CosmicEmu.names:

setattr(CosmicEmu, i, Instance(Slider)) # they are all None, and create will fail

Which is particularly annoying, because I have a list of attributes that might change and I want to programmatically add the sliders.

Sorry, these questions are probably getting out of scope of the original question, but they are all inter related because I don’t understand how the bokeh-server wants plots to be made.

2 things

1.  on a Plot instance, the attribute you need to set is plot_width

and plot_height, not height and width (I know… not that intuitive,
but a limitation of some of our glyph function signatures (rect and
such take heigh/width as parameters))
2. I’m not sure how you can define properties dynamically like that
in Bokeh (Matteusz might know) However in this case I would not do
that

In your case I would do something like the following (in pseudocode)

class CosmicEmu(HBox):
    @classmethod
    def create(cls, names):
        sliders = VBox()
        for n in names:
            slider = Slider(name=name, max=1, min=0)
            sliders.children.append(slider)
        self.children.append(sliders)
        self.children.append(someplot)
    def setup_events(self):
        if len(self.children) > 0:
            sliders = self.children[0]
            for s in sliders:
                s.on_change('value', self, 'slider_change')
    def slider_change(self, obj, attrname, old, new):
        # alter plot here
  
Is what I would do.  Note that there is no automatic conversion

between properties and any sort of visual representaiton. The
Javascript View code knows how to layout an HBox by rendering views
for each of the children. In this case I’m creating a VBox, adding
a bunch of sliders to it. Then I am adding someplot along side the
vertical box full of sliders.

I'm sorry for the trouble you're having.  We're working on making

this part of bokeh easier to use in the future

···

On 12/02/2014 02:25 PM, Jon Woodring
wrote:

    One final confusion with how classes work in

bokeh-server is that this doesn’t work:

class CosmicEmu(HBox):

…some stuff

        # some additional class

initializers

        CosmicEmu.names =

[‘omega_b’, ‘omega_m’, ‘n_s’, ‘h’, ‘w’, ‘sigma_8’, ‘z’]

        for i in

CosmicEmu.names:

            setattr(CosmicEmu,

i, Instance(Slider)) # they are all None, and create will
fail

      Which is particularly annoying, because I have a list of

attributes that might change and I want to programmatically
add the sliders.

      Sorry, these questions are probably getting out of scope of

the original question, but they are all inter related because
I don’t understand how the bokeh-server wants plots to be
made.

  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/37c0b7b9-de75-49a1-84a3-64a336b34e9b%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/37c0b7b9-de75-49a1-84a3-64a336b34e9b%40continuum.io?utm_medium=email&utm_source=footer).

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

FWIW, setting additional properties on the class after the fact does not
work because all of the Instance() and other properties are processed via
the metaclass (
https://github.com/bokeh/bokeh/blob/master/bokeh/properties.py#L452). We
could conceivably add a method to the HasProps base class to dynamically
add properties and facilitate the dynamic/programmatic construction of
bokeh model classes. I don't think it would be very hard. (There would be
the question of what to do if a JSON representation of a previous version
of such a class already exists on the server....)

-Peter

···

On Tue, Dec 2, 2014 at 1:47 PM, Hugo Shi <[email protected]> wrote:

2. I'm not sure how you can define properties dynamically like that in
Bokeh (Matteusz might know) However in this case I would not do that

  1. Actually, I was trying to set the width and height of the individual glyphs in the rect plot. How would I do that? (This was my work around that I couldn’t get an image to update in an image plot and am using a rect plot, instead, with points for each pixel.)

  2. I guess I was thinking that the class code required some sort of Instance(Slider) invocation. I didn’t consider just adding sliders to a VBox. Thanks.

···

On Tuesday, December 2, 2014 12:47:08 PM UTC-7, Hugo Shi wrote:

  On 12/02/2014 02:25 PM, Jon Woodring > wrote:
    One final confusion with how classes work in

bokeh-server is that this doesn’t work:

class CosmicEmu(HBox):

…some stuff

        # some additional class

initializers

        CosmicEmu.names =

[‘omega_b’, ‘omega_m’, ‘n_s’, ‘h’, ‘w’, ‘sigma_8’, ‘z’]

        for i in

CosmicEmu.names:

            setattr(CosmicEmu,

i, Instance(Slider)) # they are all None, and create will
fail

      Which is particularly annoying, because I have a list of

attributes that might change and I want to programmatically
add the sliders.

      Sorry, these questions are probably getting out of scope of

the original question, but they are all inter related because
I don’t understand how the bokeh-server wants plots to be
made.

  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/37c0b7b9-de75-49a1-84a3-64a336b34e9b%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/37c0b7b9-de75-49a1-84a3-64a336b34e9b%40continuum.io?utm_medium=email&utm_source=footer).

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

2 things

1.  on a Plot instance, the attribute you need to set is plot_width

and plot_height, not height and width (I know… not that intuitive,
but a limitation of some of our glyph function signatures (rect and
such take heigh/width as parameters))

2.  I'm not sure how you can define properties dynamically like that

in Bokeh (Matteusz might know) However in this case I would not do
that

In your case I would do something like the following (in pseudocode)



class CosmicEmu(HBox):

    @classmethod

    def create(cls, names):

        sliders = VBox()

        for n in names:

            slider = Slider(name=name, max=1, min=0)

            sliders.children.append(slider)

        self.children.append(sliders)

        self.children.append(someplot)

    def setup_events(self):

        if len(self.children) > 0:

            sliders = self.children[0]

            for s in sliders:

                s.on_change('value', self, 'slider_change')

    def slider_change(self, obj, attrname, old, new):

        # alter plot here

  

Is what I would do.  Note that there is no automatic conversion

between properties and any sort of visual representaiton. The
Javascript View code knows how to layout an HBox by rendering views
for each of the children. In this case I’m creating a VBox, adding
a bunch of sliders to it. Then I am adding someplot along side the
vertical box full of sliders.

I'm sorry for the trouble you're having.  We're working on making

this part of bokeh easier to use in the future

To be more specific, I need to change the size of the rect glyph dynamically, because the scaling of the axes might change.

If I inspect a Plot object, I do not see the width and height properties of the rect plot object.

i.e.

obj.image = rect('x', 'y', tools=toolset, source=obj.image_source,

                   plot_width=400, plot_height=400, color='v',

                   title='Distance Image', width=w, height=h)

if i do dir(obj.image) it doesn’t have any of the properties that I expect to be able to change the rect plot.

Where do I find these to modify an existing plot?

Jon,

Does each rect have its own width/height? That is, are the values coming from columns in a column data source? If so, you need to update the data in the data source, and that will cause the plot to update. Here is an example of updating a data source:

  https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py

If you are passing single scalar values for the width and height that get used by all rects (but that might change later) then you need to change the width and height properties of the *renderer* itself. Something like:

  obj.image = rect(..., name="foo")

        r = obj.image.select(dict(name="foo")) # returns a list of plot objects with name "foo"
        r[0].width = new_width
  r[0].height = new_height

Then store the renderer object on the session, similar to storing the data source in the example above.

Bryan

···

On Dec 3, 2014, at 11:34 AM, Jon Woodring <[email protected]> wrote:

To be more specific, I need to change the size of the rect glyph dynamically, because the scaling of the axes might change.

If I inspect a Plot object, I do not see the width and height properties of the rect plot object.

i.e.
    obj.image = rect('x', 'y', tools=toolset, source=obj.image_source,
                       plot_width=400, plot_height=400, color='v',
                       title='Distance Image', width=w, height=h)
  
if i do dir(obj.image) it doesn't have any of the properties that I expect to be able to change the rect plot.

Where do I find these to modify an existing plot?

--
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/093fda81-4b78-4d69-9443-4bfec0acac2a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

The latter with single scalar values that might change. That’s exactly what I needed, thanks much.

···

On Wednesday, December 3, 2014 10:51:05 AM UTC-7, Bryan Van de ven wrote:

Jon,

Does each rect have its own width/height? That is, are the values coming from columns in a column data source? If so, you need to update the data in the data source, and that will cause the plot to update. Here is an example of updating a data source:

    [https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py)

If you are passing single scalar values for the width and height that get used by all rects (but that might change later) then you need to change the width and height properties of the renderer itself. Something like:

    obj.image = rect(..., name="foo")



    r = obj.image.select(dict(name="foo")) # returns a list of plot objects with name "foo"

    r[0].width = new_width

    r[0].height = new_height

Then store the renderer object on the session, similar to storing the data source in the example above.

Bryan

On Dec 3, 2014, at 11:34 AM, Jon Woodring [email protected] wrote:

To be more specific, I need to change the size of the rect glyph dynamically, because the scaling of the axes might change.

If I inspect a Plot object, I do not see the width and height properties of the rect plot object.

i.e.

obj.image = rect('x', 'y', tools=toolset, source=obj.image_source,
                   plot_width=400, plot_height=400, color='v',
                   title='Distance Image', width=w, height=h)

if i do dir(obj.image) it doesn’t have any of the properties that I expect to be able to change the rect plot.

Where do I find these to modify an existing plot?


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/093fda81-4b78-4d69-9443-4bfec0acac2a%40continuum.io.

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

BTW, for my particular use case, I have to get the glyph attribute (for reference for others):

obj.image = rect(…, name=‘foo’)

rs = obj.image.select(dict(name=‘foo’))

rs[0].glyph.width = new_width

rs[0].glyph.height = new_height

Yes, actually my apologies. The renderer actually has a glyph, and it is the glyph that needs its attributes updated.

Bryan

···

On Dec 3, 2014, at 2:39 PM, Jon Woodring <[email protected]> wrote:

BTW, for my particular use case, I have to get the glyph attribute (for reference for others):

obj.image = rect(..., name='foo')
rs = obj.image.select(dict(name='foo'))

rs[0].glyph.width = new_width
rs[0].glyph.height = new_height

--
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/d8b7b8d6-a0aa-4622-a8c1-87f42055d793%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.