Change x_range of a plot depending on the value of a Select.

Hello I am trying to update a plot so that the x_range is a Factor range instead of DataRange1d. It isn’t working yet doesn’t seem to want to throw and errors. This a simplifed version of the approach I’m taking to do this, any input on better ways/ correct ways would be great appreciated.

if xVal in discrete:
p.x_range = FactorRange(factors=[‘A’,‘A+’,‘B’])

Note that these aren’t the factors I want to use but I can’t even get it to work when I hard code the factors in like so.

Thanks.

Sean

Hi,

There's not enough information here to go on:

* What are the errors (exactly)?
* Are you trying to set once at the start, or update something existing?

In general, it is advised to always provide a complete, minimal reproducing script to help others help you. Otherwise, without details, all that can be done is to point you at lots of docs and examples of using factor ranges here:

  https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html

Thanks

Bryan

···

On Feb 19, 2019, at 11:27, Sean Gallagher <[email protected]> wrote:

Hello I am trying to update a plot so that the x_range is a Factor range instead of DataRange1d. It isn't working yet doesn't seem to want to throw and errors. This a simplifed version of the approach I'm taking to do this, any input on better ways/ correct ways would be great appreciated.

  if xVal in discrete:
            p.x_range = FactorRange(factors=['A','A+','B'])

Note that these aren't the factors I want to use but I can't even get it to work when I hard code the factors in like so.

Thanks.
Sean

--
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/582d011f-a0b6-44d4-9da9-1bb865286d40%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hey Bryan,

Thank you for your quick response! I am sorry for the lack of information, unfortunately I don’t have a reproducible script at the moment I will considering making one and posting it if I can’t make any progress.

To answer the questions you posed, unfortunately I don’t know the exact errors, I am running the script in Juypter Lab and isn’t reporting any errors to me. And this code is trying to update an already created figure the update is called when some selectors are changed.

Here is a larger portion of my code, that hopefully gives you a better understanding:

def modify_doc(doc):
#Input controls
x_axis = Select(title=‘X axis’, options=raw.columns.to_list(), value=‘lvd’)
y_axis = Select(title=‘Y axis’, options=raw.columns.to_list(), value=‘lvdk’)
sex_map = {‘Male’:[‘H’,‘R’,‘G’,‘C’], ‘Female’:[‘M’,‘F’], ‘All’:[‘H’,‘R’,‘G’,‘C’,‘M’,‘F’]}
sex = Select(title=‘Sex’, options=[‘Male’, ‘Female’, ‘All’], value=‘All’)

source = ColumnDataSource(data=dict(x=[], y=[]))

p = figure(plot_height=600, plot_width=700, title="Cardiac Data Exploration", toolbar_location=None)
p.scatter(x='x', y='y', source = source)

def update():
    xVal = x_axis.value
    yVal = y_axis.value
    p.xaxis.axis_label = xVal
    p.yaxis.axis_label = yVal
   
    source.data = dict(
        x=raw.loc[raw['sex'].isin(sex_map[sex.value]), xVal],
        y=raw.loc[raw['sex'].isin(sex_map[sex.value]), yVal]
    )
   
    global temp
   
    if xVal in discrete:
        temp = FactorRange(factors=['A+','A','B'])
        p.x_range = FactorRange(factors=['A','A+','B'])
    if yVal in discrete:
        p.y_range = set(source.data['y'].tolist())

controls = [x_axis, y_axis, sex]
for control in controls:
    control.on_change('value', lambda attr, old, new: update())
   
l = layout([
    [p, controls]
])

update()
doc.add_root(l)

If it’s still not enough to go off of with out a reproducible script I understand! Thanks agian,

Sean

···

On Tuesday, February 19, 2019 at 2:32:38 PM UTC-5, Bryan Van de ven wrote:

Hi,

There’s not enough information here to go on:

  • What are the errors (exactly)?

  • Are you trying to set once at the start, or update something existing?

In general, it is advised to always provide a complete, minimal reproducing script to help others help you. Otherwise, without details, all that can be done is to point you at lots of docs and examples of using factor ranges here:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html](https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html)

Thanks

Bryan

On Feb 19, 2019, at 11:27, Sean Gallagher [email protected] wrote:

Hello I am trying to update a plot so that the x_range is a Factor range instead of DataRange1d. It isn’t working yet doesn’t seem to want to throw and errors. This a simplifed version of the approach I’m taking to do this, any input on better ways/ correct ways would be great appreciated.

if xVal in discrete:

        p.x_range = FactorRange(factors=['A','A+','B'])

Note that these aren’t the factors I want to use but I can’t even get it to work when I hard code the factors in like so.

Thanks.

Sean


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/582d011f-a0b6-44d4-9da9-1bb865286d40%40continuum.io.

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