本文整理汇总了Python中bokeh.models.Select类的典型用法代码示例。如果您正苦于以下问题:Python Select类的具体用法?Python Select怎么用?Python Select使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modify_doc
def modify_doc(doc):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Circle(x='x', y='y', size=20))
plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
select = Select(options=["Option 1", "Option 2", "Option 3"], css_classes=["foo"])
def cb(attr, old, new):
source.data['val'] = [old, new]
select.on_change('value', cb)
doc.add_root(column(select, plot))
示例2: plotDayOfWeekTimeline
def plotDayOfWeekTimeline(fileName, initData, bokehPlaceholderId='bokehContent'):
source = ColumnDataSource(data=initData)
selectDOW = Select(title="Days:", value="Monday", options=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
selectUT = Select(title="User Type:", value="All", options=["All", "Subscriber", "Customer"])
model = dict(source=source, select_dow = selectDOW, select_ut = selectUT)
plot = Figure(plot_width=1200, plot_height=400, x_axis_type="datetime")
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
callback = CustomJS(args=model, code="""
var dayOfWeek = select_dow.get('value')
var userType = select_ut.get('value')
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
var data = source.get('data');
var result = JSON.parse(xmlhttp.responseText);
var temp=[];
for(var date in result.x) {
temp.push(new Date(result.x[date]));
}
data['x'] = temp;
data['y'] = result.y;
source.trigger('change');
}
else if(xmlhttp.status == 400) {
alert(400);
}
else {
alert(xmlhttp.status);
}
}
};
var params = {dow:dayOfWeek, ut:userType};
url = "/select?" + jQuery.param( params );
xmlhttp.open("GET", url, true);
xmlhttp.send();
""")
selectDOW.callback = callback
selectUT.callback = callback
layout = vform(selectDOW, selectUT, plot)
script, div = components(layout)
html = readHtmlFile(fileName)
html = insertScriptIntoHeader(html, script)
html = appendElementContent(html, div, "div", "bokehContent")
return html
示例3: __init__
def __init__(self, worker, **kwargs):
with log_errors():
self.worker = worker
names = ['nbytes', 'duration', 'bandwidth', 'count', 'type',
'inout-color', 'type-color', 'key', 'key-color', 'start',
'stop']
quantities = ['nbytes', 'duration', 'bandwidth', 'count',
'start', 'stop']
colors = ['inout-color', 'type-color', 'key-color']
# self.source = ColumnDataSource({name: [] for name in names})
self.source = ColumnDataSource({
'nbytes': [1, 2],
'duration': [0.01, 0.02],
'bandwidth': [0.01, 0.02],
'count': [1, 2],
'type': ['int', 'str'],
'inout-color': ['blue', 'red'],
'type-color': ['blue', 'red'],
'key': ['add', 'inc'],
'start': [1, 2],
'stop': [1, 2]
})
self.x = Select(title='X-Axis', value='nbytes', options=quantities)
self.x.on_change('value', self.update_figure)
self.y = Select(title='Y-Axis', value='bandwidth', options=quantities)
self.y.on_change('value', self.update_figure)
self.size = Select(title='Size', value='None',
options=['None'] + quantities)
self.size.on_change('value', self.update_figure)
self.color = Select(title='Color', value='inout-color',
options=['black'] + colors)
self.color.on_change('value', self.update_figure)
if 'sizing_mode' in kwargs:
kw = {'sizing_mode': kwargs['sizing_mode']}
else:
kw = {}
self.control = widgetbox([self.x, self.y, self.size, self.color],
width=200, **kw)
self.last_outgoing = 0
self.last_incoming = 0
self.kwargs = kwargs
self.layout = row(self.control, self.create_figure(**self.kwargs),
**kw)
self.root = self.layout
示例4: test_js_on_change_executes
def test_js_on_change_executes(self, bokeh_model_page):
select = Select(options=["Option 1", "Option 2", "Option 3"], css_classes=["foo"])
select.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))
page = bokeh_model_page(select)
el = page.driver.find_element_by_css_selector('.foo select')
el.click()
el = page.driver.find_element_by_css_selector('.foo select option[value="Option 3"]')
el.click()
results = page.results
assert results['value'] == 'Option 3'
assert page.has_no_console_errors()
示例5: create_layout
def create_layout(self):
# create figure
self.x_range = Range1d(start=self.model.map_extent[0],
end=self.model.map_extent[2], bounds=None)
self.y_range = Range1d(start=self.model.map_extent[1],
end=self.model.map_extent[3], bounds=None)
self.fig = Figure(tools='box_zoom,wheel_zoom,pan', x_range=self.x_range,
y_range=self.y_range)
self.fig.plot_height = 600
self.fig.plot_width = 1024
self.fig.axis.visible = True
# add datashader layer
self.image_source = ImageSource(url=self.model.service_url,
extra_url_vars=self.model.shader_url_vars)
self.image_renderer = DynamicImageRenderer(image_source=self.image_source)
self.fig.renderers.append(self.image_renderer)
# add ui components
axes_select = Select.create(name='Plot:',
options=self.model.axes)
axes_select.on_change('value', self.on_axes_change)
field_select = Select.create(name='Summary:', options=self.model.fields)
field_select.on_change('value', self.on_field_change)
aggregate_select = Select.create(name='Aggregation:',
options=self.model.aggregate_functions)
aggregate_select.on_change('value', self.on_aggregate_change)
transfer_select = Select.create(name='Scale:',
options=self.model.transfer_functions)
transfer_select.on_change('value', self.on_transfer_function_change)
controls = [axes_select, field_select, aggregate_select,
transfer_select]
self.controls = VBox(width=200, height=600, children=controls)
self.map_area = VBox(width=self.fig.plot_width, children=[self.fig])
self.layout = HBox(width=self.fig.plot_width, children=[self.controls, self.map_area])
示例6: bball
def bball():
os.chdir('C:\\Users\\weinfz18\\Documents\\NBA_current') ## switch to correct directory
imgo = np.loadtxt('imgo.csv', delimiter=',')
imgd = np.loadtxt('imgd.csv', delimiter=',')
## court image
players = pd.read_csv('C:\\Users\\weinfz18\\Documents\\NBA_current\\all_players.csv', names=['players'],delimiter='$')
oplayer = "Whiteside, Hassan"
dplayer = "Whiteside, Hassan"
dplayername = ''.join([x for x in dplayer.lower() if x in 'abcdefghijklmnopqrstuvwxyz'])
oplayername = ''.join([x for x in oplayer.lower() if x in 'abcdefghijklmnopqrstuvwxyz'])
odata = pd.read_csv('C:\\Users\\weinfz18\\Documents\\NBA_current\\player_shots\\{}\\odata.csv'.format(oplayername))
ddata = pd.read_csv('C:\\Users\\weinfz18\\Documents\\NBA_current\\player_shots\\{}\\ddata.csv'.format(dplayername))
odata = odata[odata['dense']!=0]
ddata = ddata[ddata['dense']!=0]
ddata = ddata.reset_index(drop=True)
odata = odata.reset_index(drop=True)
odata = odata.to_dict("list")
ddata = ddata.to_dict("list")
oplayer_select = Select(value="Rubio, Ricky", title='Offensive player', options=sorted(players['players'].tolist()))
dplayer_select = Select(value="Rubio, Ricky", title='Defensive player', options=sorted(players['players'].tolist()))
oplayer_select.on_change('value', update_plot)
dplayer_select.on_change('value', update_plot)
op, odata_table, dp, ddata_table = Make_Plot(ddata,odata,imgo,imgd,oplayer,dplayer)
oscript, odiv = components(op)
otscript, otdiv = components(odata_table)
dscript, ddiv = components(dp)
dtscript, dtdiv = components(ddata_table)
script = [oscript, otscript, dscript, dtscript]
div = [odiv, otdiv, ddiv, dtdiv]
return render_template('index.html', script=script, div=div)
示例7: create_layout
def create_layout():
year_select = Select(title="Year:", value="2010", options=years)
location_select = Select(title="Location:", value="World", options=locations)
year_select.on_change('value', on_year_change)
location_select.on_change('value', on_location_change)
controls = row(children=[year_select, location_select])
layout = column(children=[controls, pyramid(), population()])
return layout
示例8: create_layout
def create_layout(self):
years = list(map(str, sorted(self.df.Year.unique())))
locations = sorted(self.df.Location.unique())
year_select = Select(title="Year:", value="2010", options=years)
location_select = Select(title="Location:", value="World", options=locations)
year_select.on_change('value', self.on_year_change)
location_select.on_change('value', self.on_location_change)
controls = HBox(year_select, location_select)
self.layout = VBox(controls, self.plot)
示例9: create_layout
def create_layout():
size_select = Select(
value="Days Active", title="Marker Scaling:", options=["Days Active", "Days Remaining", "Power Output"]
)
size_select.on_change("value", on_size_change)
location_select = Select(title="Power Plant Name:", value=location, options=locations)
location_select.on_change("value", on_location_change)
controls = HBox(children=[size_select, location_select])
layout = VBox(children=[controls, map(), performance()])
return layout
示例10: create_view_widget
def create_view_widget(self):
self.w_view = Select(title="View:", value="", options=[], width=5)
self.w_view.on_change('value', self.on_view_widget_change)
self.layout = column([self.w_view, self.layout])
示例11: BokehEventViewerWaveform
#.........这里部分代码省略.........
self.fig.add_layout(self.intwin1)
self.fig.add_layout(self.intwin2)
def _set_integration_window(self):
e = self.event
t = self.telid
c = self.channel
p = self.pixel
if e:
if e.dl1.tel[t].extracted_samples is not None:
# Get Windows
windows = e.dl1.tel[t].extracted_samples[c, p]
length = np.sum(windows)
start = np.argmax(windows)
end = start + length - 1
self.intwin1.location = start
self.intwin2.location = end
else:
self.event_viewer.log.warning("No event has been provided")
def refresh(self):
self._set_waveform()
self._set_integration_window()
@property
def event(self):
return self._event
@event.setter
def event(self, val):
self._event = val
self._set_waveform()
self._set_integration_window()
def change_event(self, event, telid):
if self.event: # Only reset when an event exists
self._reset()
self._telid = telid
self.event = event
@property
def view(self):
return self._view
@view.setter
def view(self, val):
if val not in list(self._view_options.keys()):
raise ValueError(f"View is not valid: {val}")
self._view = val
self._set_waveform()
self._set_integration_window()
@property
def telid(self):
return self._telid
@telid.setter
def telid(self, val):
if self.event: # Only reset when an event exists
self._reset()
self._telid = val
self._set_waveform()
self._set_integration_window()
@property
def channel(self):
return self._channel
@channel.setter
def channel(self, val):
self._channel = val
self._set_waveform()
self._set_integration_window()
@property
def pixel(self):
return self._pixel
@pixel.setter
def pixel(self, val):
self._pixel = val
self._set_waveform()
self._set_integration_window()
def _on_waveform_click(self, time):
super()._on_waveform_click(time)
self.event_viewer.change_time(time)
def create_view_widget(self):
self.w_view = Select(title="View:", value="", options=[], width=5)
self.w_view.on_change('value', self.on_view_widget_change)
self.layout = column([self.w_view, self.layout])
def update_view_widget(self):
self.w_view.options = list(self._view_options.keys())
self.w_view.value = self.view
def on_view_widget_change(self, _, __, ___):
if self.view != self.w_view.value:
self.view = self.w_view.value
示例12: create_layout
def create_layout(self):
# create figure
self.x_range = Range1d(start=self.model.map_extent[0],
end=self.model.map_extent[2], bounds=None)
self.y_range = Range1d(start=self.model.map_extent[1],
end=self.model.map_extent[3], bounds=None)
self.fig = Figure(tools='wheel_zoom,pan',
x_range=self.x_range,
lod_threshold=None,
plot_width=self.model.plot_width,
plot_height=self.model.plot_height,
y_range=self.y_range)
self.fig.min_border_top = 0
self.fig.min_border_bottom = 10
self.fig.min_border_left = 0
self.fig.min_border_right = 0
self.fig.axis.visible = False
self.fig.xgrid.grid_line_color = None
self.fig.ygrid.grid_line_color = None
# add tiled basemap
self.tile_source = WMTSTileSource(url=self.model.basemap)
self.tile_renderer = TileRenderer(tile_source=self.tile_source)
self.fig.renderers.append(self.tile_renderer)
# add datashader layer
self.image_source = ImageSource(url=self.model.service_url,
extra_url_vars=self.model.shader_url_vars)
self.image_renderer = DynamicImageRenderer(image_source=self.image_source)
self.fig.renderers.append(self.image_renderer)
# add label layer
self.label_source = WMTSTileSource(url=self.model.labels_url)
self.label_renderer = TileRenderer(tile_source=self.label_source)
self.fig.renderers.append(self.label_renderer)
# Add a hover tool
hover_layer = HoverLayer()
hover_layer.field_name = self.model.field_title
hover_layer.is_categorical = self.model.field in self.model.categorical_fields
self.fig.renderers.append(hover_layer.renderer)
self.fig.add_tools(hover_layer.tool)
self.model.hover_layer = hover_layer
self.model.legend_side_vbox = VBox()
self.model.legend_bottom_vbox = VBox()
# add ui components
controls = []
axes_select = Select.create(name='Axes',
options=self.model.axes)
axes_select.on_change('value', self.on_axes_change)
controls.append(axes_select)
self.field_select = Select.create(name='Field', options=self.model.fields)
self.field_select.on_change('value', self.on_field_change)
controls.append(self.field_select)
self.aggregate_select = Select.create(name='Aggregate',
options=self.model.aggregate_functions)
self.aggregate_select.on_change('value', self.on_aggregate_change)
controls.append(self.aggregate_select)
transfer_select = Select.create(name='Transfer Function',
options=self.model.transfer_functions)
transfer_select.on_change('value', self.on_transfer_function_change)
controls.append(transfer_select)
color_ramp_select = Select.create(name='Color Ramp', options=self.model.color_ramps)
color_ramp_select.on_change('value', self.on_color_ramp_change)
controls.append(color_ramp_select)
spread_size_slider = Slider(title="Spread Size (px)", value=0, start=0,
end=10, step=1)
spread_size_slider.on_change('value', self.on_spread_size_change)
controls.append(spread_size_slider)
hover_size_slider = Slider(title="Hover Size (px)", value=8, start=4,
end=30, step=1)
hover_size_slider.on_change('value', self.on_hover_size_change)
controls.append(hover_size_slider)
controls.append(self.model.legend_side_vbox)
# add map components
basemap_select = Select.create(name='Basemap', value='Imagery',
options=self.model.basemaps)
basemap_select.on_change('value', self.on_basemap_change)
image_opacity_slider = Slider(title="Opacity", value=100, start=0,
end=100, step=1)
image_opacity_slider.on_change('value', self.on_image_opacity_slider_change)
basemap_opacity_slider = Slider(title="Basemap Opacity", value=100, start=0,
end=100, step=1)
basemap_opacity_slider.on_change('value', self.on_basemap_opacity_slider_change)
#.........这里部分代码省略.........
示例13: figure
# Create a new plot: plot
plot = figure()
# Add circles to the plot
plot.circle('x', 'y', source=source)
# Define a callback function: update_plot
def update_plot(attr, old, new):
# If the new Selection is 'female_literacy', update 'y' to female_literacy
if new == 'female_literacy':
source.data = {
'x' : fertility,
'y' : female_literacy
}
# Else, update 'y' to population
else:
source.data = {
'x' : fertility,
'y' : population
}
# Create a dropdown Select widget: select
select = Select(title="distribution", options=['female_literacy', 'population'], value='female_literacy')
# Attach the update_plot callback to the 'value' property of select
select.on_change('value', update_plot)
# Create layout and add to current document
layout = row(select, plot)
curdoc().add_root(layout)
开发者ID:shonkhochil,项目名称:Coursera-Repo,代码行数:30,代码来源:06-updating-data-sources-from-dropdown-callbacks.py
示例14: Select
cities = {
'Austin': {
'airport': 'AUS',
'title': 'Austin, TX',
},
'Boston': {
'airport': 'BOS',
'title': 'Boston, MA',
},
'Seattle': {
'airport': 'SEA',
'title': 'Seattle, WA',
}
}
city_select = Select(value=city, title='City', options=sorted(cities.keys()))
distribution_select = Select(value=distribution, title='Distribution', options=['Discrete', 'Smooth'])
df = pd.read_csv(join(dirname(__file__), 'data/2015_weather.csv'))
source = get_dataset(df, cities[city]['airport'], distribution)
plot = make_plot(source, cities[city]['title'])
city_select.on_change('value', update_plot)
distribution_select.on_change('value', update_plot)
controls = VBox(city_select, distribution_select)
# add to document
curdoc().add_root(HBox(controls, plot))
示例15: create_layout
def create_layout(self):
# create figure
self.x_range = Range1d(start=self.model.map_extent[0],
end=self.model.map_extent[2], bounds=None)
self.y_range = Range1d(start=self.model.map_extent[1],
end=self.model.map_extent[3], bounds=None)
self.fig = Figure(tools='wheel_zoom,pan',
x_range=self.x_range,
lod_threshold=None,
plot_width=self.model.plot_width,
plot_height=self.model.plot_height,
y_range=self.y_range)
self.fig.min_border_top = 0
self.fig.min_border_bottom = 10
self.fig.min_border_left = 0
self.fig.min_border_right = 0
self.fig.axis.visible = False
self.fig.xgrid.grid_line_color = None
self.fig.ygrid.grid_line_color = None
# add tiled basemap
self.tile_source = WMTSTileSource(url=self.model.basemap)
self.tile_renderer = TileRenderer(tile_source=self.tile_source)
self.fig.renderers.append(self.tile_renderer)
# add datashader layer
self.image_source = ImageSource(url=self.model.service_url,
extra_url_vars=self.model.shader_url_vars)
self.image_renderer = DynamicImageRenderer(image_source=self.image_source)
self.fig.renderers.append(self.image_renderer)
# add label layer
self.label_source = WMTSTileSource(url=self.model.labels_url)
self.label_renderer = TileRenderer(tile_source=self.label_source)
self.fig.renderers.append(self.label_renderer)
# Add a hover tool
self.invisible_square = Square(x='x',
y='y',
fill_color=None,
line_color=None,
size=self.model.hover_size)
self.visible_square = Square(x='x',
y='y',
fill_color='#79DCDE',
fill_alpha=.5,
line_color='#79DCDE',
line_alpha=1,
size=self.model.hover_size)
cr = self.fig.add_glyph(self.model.hover_source,
self.invisible_square,
selection_glyph=self.visible_square,
nonselection_glyph=self.invisible_square)
code = "source.set('selected', cb_data['index']);"
callback = CustomJS(args={'source': self.model.hover_source}, code=code)
self.model.hover_tool = HoverTool(tooltips=[(self.model.fields.keys()[0], "@value")],
callback=callback,
renderers=[cr],
mode='mouse')
self.fig.add_tools(self.model.hover_tool)
self.model.legend_side_vbox = VBox()
self.model.legend_bottom_vbox = VBox()
# add ui components
controls = []
axes_select = Select.create(name='Axes',
options=self.model.axes)
axes_select.on_change('value', self.on_axes_change)
controls.append(axes_select)
self.field_select = Select.create(name='Field', options=self.model.fields)
self.field_select.on_change('value', self.on_field_change)
controls.append(self.field_select)
self.aggregate_select = Select.create(name='Aggregate',
options=self.model.aggregate_functions)
self.aggregate_select.on_change('value', self.on_aggregate_change)
controls.append(self.aggregate_select)
transfer_select = Select.create(name='Transfer Function',
options=self.model.transfer_functions)
transfer_select.on_change('value', self.on_transfer_function_change)
controls.append(transfer_select)
color_ramp_select = Select.create(name='Color Ramp', options=self.model.color_ramps)
color_ramp_select.on_change('value', self.on_color_ramp_change)
controls.append(color_ramp_select)
spread_size_slider = Slider(title="Spread Size (px)", value=0, start=0,
end=10, step=1)
spread_size_slider.on_change('value', self.on_spread_size_change)
controls.append(spread_size_slider)
#.........这里部分代码省略.........