On Apr 12, 2016, at 6:59 PM, Scott Ming <[email protected]> wrote:
HI, Bryan.
Yes, That's What I want. Thank you very much. How do I hide the x_ticks? Whether the Bar Charts could do it?
16-4-13 08:07
2016-04-12 12:54 GMT+08:00 Bryan Van de Ven <[email protected]>:
Scott,
There are a couple of things amiss in your code:
* left and right were both 1, you had an invisible or nearly invisible zero width quad
* you have to explicitly re-assign to data['y'] in the callback, there are not references like python
* you need to assign a length one array, you were making a longer array each time (think list replication in python: [10] * 3 = [10, 10, 10])
* "f * y" grows without bound, it never gets smaller, I think maybe you just want the top to be slider value?
Here is your code, edited to do roughly what I imagine you want:
from bokeh.plotting import Figure, output_file, show, figure
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource, Slider
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
output_file("foo.html")
y = 1
df = DataFrame({'y': [y]})
source = ColumnDataSource(data=dict(y=[1]))
plot = figure(plot_width=400, plot_height=400, x_range=[0, 5], y_range=[0, 20])
plot.quad(top='y', bottom=0, left=0, right=1, color="red", source=source)
def callback(source=source):
data = source.get('data')
f = cb_obj.get('value')
y = data['y'][0]
data['y'] = [f]
source.trigger('change')
slider = Slider(start=1, end=10, value=1, step=1, title="power",
callback=CustomJS.from_py_func(callback))
layout = vform(slider, plot)
show(layout)
> On Apr 11, 2016, at 6:47 PM, Scott Ming <[email protected]> wrote:
>
> Hi, Bryan.
>
> Thanks for your help, I changed my code after you answer me, but the plot can't grow too. I don't know why. I hope you can tell me more error of my code.
>
> This is my new code:
> ```
> from bokeh.plotting import Figure, output_notebook, show, figure
> from bokeh.io import vform
> from bokeh.models import CustomJS, ColumnDataSource, Slider
> import numpy as np
> import pandas as pd
> from pandas import Series, DataFrame
>
> output_notebook()
>
> y = 1
> df = DataFrame({'y': [y]})
> source = ColumnDataSource(data=df)
>
> plot = figure(plot_width=400, plot_height=400, x_range=[0, 5], y_range=[0, 20])
> plot.quad(top='y', bottom=0, left=1, right=1, color="red", source=source)
>
>
> def callback(source=source):
> data = source.get('data')
> f = cb_obj.get('value')
> y = data['y']
> y = f * y
>
> source.trigger('change')
>
> slider = Slider(start=1, end=10, value=1, step=1, title="power",
> callback=CustomJS.from_py_func(callback))
>
> layout = vform(slider, plot)
>
> show(layout)
> ```
>
> Could you give me more code, or some examples of quad plot with interactions.
>
> Thanks,
>
> Scott
>
> 2016-04-11 23:01 GMT+08:00 Bryan Van de Ven <[email protected]>:
> At the lowest level all the coordinates for glyphs have to be one of two things:
>
> * a literal number, i.e. y = 10
> * a string column name, i.e. y = "price"
>
> As a convenience, when you pass a literal sequence like y=[1,2,3] to a glyph method like Figure.quad, Bokeh will create a new column in the glyph renderers data source to store the data, and give it an internal name that is used as the column name. This is why things are not working for you, the "automatically created" column has some random name, is not named "y", which is the column you are updated. Your quad glyph needs to configured with the *name* of the column in the data source you are explicitly passing in, something like:
>
> plot.quad(top="y", bottom=0, left=1, right=1, color="red", source=source)
>
> Note also: I have changed all the other properties to literal numbers instead of lists (e.g., left=1 instead of left=[1]) because this kind of mixing automatically created columns, with an explicitly passed in source, an lead to much confusion and error situations, and will *almost certainly be explicitly prohibited in the near future*.
>
> Thanks,
>
> Bryan
>
>
> > On Apr 11, 2016, at 9:12 AM, Scott Ming <[email protected]> wrote:
> >
> > I'm trying to build a quad plot and add interaction, I hope it can grow, but it can't work, please help me.
> > 在此输入代码...
> > from bokeh.plotting import Figure, output_notebook, show, figure
> > from bokeh.io import vform
> > from bokeh.models import CustomJS, ColumnDataSource, Slider
> >
> > y = 1
> > df = DataFrame({'y': [y]})
> > source = ColumnDataSource(data=df)
> >
> > plot = figure(plot_width=400, plot_height=400, x_range=[0, 5], y_range=[0, 20])
> > plot.quad(top=[y], bottom=[0], left=[1],
> > right=[2], color="red", source=source)
> >
> > # # plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
> >
> > def callback(source=source):
> > data = source.get('data')
> > f = cb_obj.get('value')
> > y = data['y']
> > y = f * y
> >
> > source.trigger('change')
> >
> > slider = Slider(start=1, end=10, value=1, step=1, title="power",
> > callback=CustomJS.from_py_func(callback))
> >
> > layout = vform(slider, plot)
> >
> > show(layout)
> >
> > --
> > 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/99083ed4-d9fb-4709-9172-da2793a33b9f%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/80019ED4-52E7-4A45-93EB-C2546982EF61%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/CAEpx1chYqewu4oyTVVoDyvw%3DJXxsuvEja-SMMEM1rK8QAxw1fA%40mail.gmail.com\.
> 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/634A7F50-2527-4274-8130-89DCFDB346C0%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/CAEpx1chwcexvALHaBC72b1R-bsRSCtiT5XH7zCg-V0SgRxWCxg%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.