Thanks! Can you point to any docs or examples on how to get this done? I tried using an AjaxDataSource with the BoxPlot chart, but didn't get anywhere.
On Oct 7, 2015, at 3:28 PM, Ben Cipollini <[email protected]> wrote:
I am wondering similar things about the charts interface...
On Tue, Oct 6, 2015 at 4:19 PM, waqy <[email protected]> wrote:
Thanks. That clears things a little bit.
A follow up question: Can CustomJS be used with the charts interface in 0.10? What would I use for the source? Could I pass a dataframe to the callback ?
On Tuesday, October 6, 2015 at 12:48:19 PM UTC-7, Bryan Van de ven wrote:
Sarah is correct. The .data attribute is just a dictionary that maps column names to arrays of data:
{
'x': [1,3,4,4,...],
'y1': [....],
'y2': [....],
'y3': [....]
}
To actually see any changes, you need to do one of two things:
* update the "y" property of the glyph to point to a different column
This is probably a bit difficult to to at the moment, so the other option is:
* make a special "y" column the glyph always uses, and copy data to and from it
This is much easier, here is a working example:
from bokeh.io import hplot, vplot
from bokeh.plotting import figure, output_file, show
from bokeh.models import CustomJS, ColumnDataSource, Select
import pandas as pd
import numpy as np
output_file("bkh_df.html")
df = pd.DataFrame(np.random.randn(10,3), columns=['y1','y2','y3'])
df.reset_index(inplace=True)
df.columns = ['x', 'y1', 'y2', 'y3']
df['y'] = df['y1'] # NEW
source=ColumnDataSource(data=df)
p1 = figure(plot_width=500, plot_height=300, logo=None, toolbar_location='right')
p1.circle(source=source, x='x', y='y', size=20, alpha=0.5) # CHANGED
callback = CustomJS(args=dict(source=source), code="""
var data = source.get('data');
var f = cb_obj.get('value')
data['y'] = data[f] # CHANGED
source.trigger('change');
""")
y_axis = Select(title="Y:", value='y1', options=['y1', 'y2', 'y3'], callback=callback)
show((hplot(y_axis, p1)))
On Oct 6, 2015, at 2:17 PM, waqy <[email protected]> wrote:
I think the y variable in js is the attribute of the plot. That is the one that needs updating and not data[y].
This is what I could understand by the provided bokeh example.
Interaction — Bokeh 3.3.2 Documentation
On Tuesday, October 6, 2015 at 12:08:00 PM UTC-7, Sarah Bird wrote:
You're assigning columns from data to the variables y & x, you are not updating the data frame.
you probably want to do data['y'] = data[f] or something like that.
On Tue, Oct 6, 2015 at 2:47 PM, waqy <[email protected]> wrote:
I'm trying to implement the js callback using one of the examples provided.
I have a dataframe with 3 different y columns (y1, y2, y3) and I've defined a 'Select' tool that allows me to choose the 'y' value to be plotted against the x values. I would expect the graph to change on selection, but I observe no change.
Here is the code I've used. I'm not familiar with javascript, though I've observed that the variable f does reflect what is chosen in 'Select'.
I think source.trigger('change') is not triggering a change.
from bokeh.io import hplot, vplot
from bokeh.plotting import figure, output_file, show
from bokeh.models import CustomJS, ColumnDataSource, Select
import pandas as pd
import numpy as np
output_file("bkh_df.html")
df = pd.DataFrame(np.random.randn(10,3), columns=['y1','y2','y3'])
df.reset_index(inplace=True)
df.columns = ['x', 'y1', 'y2', 'y3']
source=ColumnDataSource(data=df)
p1 = figure(plot_width=500, plot_height=300, logo=None, toolbar_location='right')
p1.circle(source=source, x='x', y='y1', size=20, alpha=0.5)
callback = CustomJS(args=dict(source=source), code="""
var data = source.get('data');
var f = cb_obj.get('value')
x = data['x']
y = data[f]
source.trigger('change');
""")
y_axis = Select(title="Y:", value='y1', options=['y1', 'y2', 'y3'], callback=callback)
show((hplot(y_axis, p1)))
--
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 bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/93ec049e-7352-422f-9569-ad5cfb9570c9%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
--
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 bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/8f61f4d9-0a7f-4068-8e64-f4ee5c6bafad%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
--
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/12f28c37-39e5-4bff-b92e-958b4785cc4b%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
--
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/CANgTvZjiPtZ_6y4ig4y3WiQiQ_%2Bv5XS7a5dXmvY_-HoAgJSoOA%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.