How to update x_range after selections from a select widget

Current x_range is a list
x_range=[‘a’,‘b’,‘c’]

After the select, new x_range should be

x_range[‘b’,‘c’,‘a’]

Please help

p = figure(title=“Sheep data Adjacency Matrix”,

x_axis_location=“above”, tools=“hover,save”,

x_range=list(reversed(names)), y_range=names,

tooltips = [(‘names’, ‘@xname win @yname’), (‘win count’, ‘@count’)])

p.rect(‘xname’, ‘yname’, 0.9, 0.9, source=data,

color=‘colors’, alpha=‘alphas’, line_color=None,

hover_line_color=‘black’, hover_color=‘colors’)

XRANGE=list(reversed(names))

temp=XRANGE[0]

XRANGE[0]=XRANGE[-1]

XRANGE[-1]=temp

def update_range(attrname, old, new):

if select.value==‘Win’:

a = figure(x_range=XRANGE)

p.x_range = a.x_range

select.on_change(‘value’, update_range)

Above code in not updating the plot with the new x_range. Please help

Hi,

Passing just a list as x_range to figure is a convenience, but it only works in the call to figure, not elsewhere. It is actually equivalent to

  figure(x_range=FactorRange(factors=['a','b','c'])), ...)

Setting just a list somewhere else later is not sufficient. You would need to either:

* create and set an entirely new FactorRange explicitly
* update the .factors on the existing range.

So which to do?

In general it is always best-practice with Bokeh to make the smallest update/change possible. This usually takes the form of "update properties of existing objects, don't replace existing objects entirely". In particular in this case, you should prefer:

  p.x_range.factors = new_factors

Thanks,

Bryan

···

On Feb 11, 2019, at 01:49, [email protected] wrote:

Current x_range is a list
x_range=['a','b','c']

After the select, new x_range should be
x_range['b','c','a']

Please help

p = figure(title="Sheep data Adjacency Matrix",
               x_axis_location="above", tools="hover,save",
               x_range=list(reversed(names)), y_range=names,
               tooltips = [('names', '@xname win @yname'), ('win count', '@count')])

p.rect('xname', 'yname', 0.9, 0.9, source=data,
           color='colors', alpha='alphas', line_color=None,
           hover_line_color='black', hover_color='colors')

XRANGE=list(reversed(names))
temp=XRANGE[0]
XRANGE[0]=XRANGE[-1]
XRANGE[-1]=temp

def update_range(attrname, old, new):
        if select.value=='Win':
            a = figure(x_range=XRANGE)
            p.x_range = a.x_range
          
select.on_change('value', update_range)

Above code in not updating the plot with the new x_range. Please help

--
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/e4fcc9dd-2dc1-4b78-b0b9-de3f02f4d6f0%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thank you very much Bryan. It worked!! :slight_smile:

···

On Monday, February 11, 2019 at 8:28:53 AM UTC-8, Bryan Van de ven wrote:

Hi,

Passing just a list as x_range to figure is a convenience, but it only works in the call to figure, not elsewhere. It is actually equivalent to

    figure(x_range=FactorRange(factors=['a','b','c'])), ...)

Setting just a list somewhere else later is not sufficient. You would need to either:

  • create and set an entirely new FactorRange explicitly

  • update the .factors on the existing range.

So which to do?

In general it is always best-practice with Bokeh to make the smallest update/change possible. This usually takes the form of “update properties of existing objects, don’t replace existing objects entirely”. In particular in this case, you should prefer:

    p.x_range.factors = new_factors

Thanks,

Bryan

On Feb 11, 2019, at 01:49, [email protected] wrote:

Current x_range is a list

x_range=[‘a’,‘b’,‘c’]

After the select, new x_range should be

x_range[‘b’,‘c’,‘a’]

Please help

p = figure(title=“Sheep data Adjacency Matrix”,

           x_axis_location="above", tools="hover,save",
           x_range=list(reversed(names)), y_range=names,
           tooltips = [('names', '@xname win @yname'), ('win count', '@count')])

p.rect(‘xname’, ‘yname’, 0.9, 0.9, source=data,

       color='colors', alpha='alphas', line_color=None,
       hover_line_color='black', hover_color='colors')

XRANGE=list(reversed(names))

temp=XRANGE[0]

XRANGE[0]=XRANGE[-1]

XRANGE[-1]=temp

def update_range(attrname, old, new):

    if select.value=='Win':
        a = figure(x_range=XRANGE)
        p.x_range = a.x_range

select.on_change(‘value’, update_range)

Above code in not updating the plot with the new x_range. Please help


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/e4fcc9dd-2dc1-4b78-b0b9-de3f02f4d6f0%40continuum.io.

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