Here are the examples of the python api bokeh.models.ZoomInTool taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
View Source File : line.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def map_plot(nx, ny, source, other=None, output_backend=MAP_BACKEND):
tools = [PanTool(dimensions='both'),
ZoomInTool(dimensions='both'), ZoomOutTool(dimensions='both'),
ResetTool(),
HoverTool(tooltips=[tooltip(x)
for x in (N.LATITUDE, N.LONGITUDE, N.DISTANCE_KM, N.LOCAL_TIME)])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny,
x_axis_type='mercator', y_axis_type='mercator', match_aspect=True, tools=tools)
add_route(f, source)
if present(other, N.SPHERICAL_MERCATOR_X, N.SPHERICAL_MERCATOR_Y):
add_route(f, other, color='black', line_dash='dotted')
f.add_tile(STAMEN_TERRAIN, alpha=0.3)
f.axis.visible = False
f.toolbar.logo = None
return f
def map_intensity(nx, ny, source, z, power=1.0, color='red', alpha=0.01, ranges=None, output_backend=MAP_BACKEND):
3
View Source File : utils.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def make_tools(y):
tools = [PanTool(dimensions='width'),
ZoomInTool(dimensions='width'), ZoomOutTool(dimensions='width'),
ResetTool(),
HoverTool(tooltips=[tooltip(x) for x in (y, N.DISTANCE_KM, N.LOCAL_TIME)])]
return tools
def make_range(column, lo=None, hi=None):
0
View Source File : health.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def std_distance_time_plot(nx, ny, source, x_range=None, output_backend=DEFAULT_BACKEND):
# avoid range errors
if len(source[N.ACTIVE_TIME_S].dropna()) < 2:
return None
groups = [group for statistic, group in related_statistics(source, N.ACTIVE_TIME)]
if not groups:
# original monochrome plot
return multi_dot_plot(nx, ny, N.TIME, [N.ACTIVE_TIME_H, N.ACTIVE_DISTANCE_KM], source,
['black', 'grey'], alphas=[1, 0.5], x_range=x_range, rescale=True)
times = [f'{N.ACTIVE_TIME}:{group}' for group in groups]
distances = [f'{N.ACTIVE_DISTANCE}:{group}' for group in groups]
time_y_range = make_range(source[N.ACTIVE_TIME_H])
distance_y_range = make_range(source[N.ACTIVE_DISTANCE_KM])
colours = list(evenly_spaced_hues(len(groups)))
tooltip_names = [N.ACTIVE_TIME_H, N.ACTIVE_DISTANCE_KM, N.ACTIVITY_GROUP, N.LOCAL_TIME]
tooltip_names += [name for name in like(N._delta(N.FITNESS_ANY), source.columns) if ':' not in name]
tooltip_names += [name for name in like(N._delta(N.FATIGUE_ANY), source.columns) if ':' not in name]
tools = [PanTool(dimensions='width'),
ZoomInTool(dimensions='width'), ZoomOutTool(dimensions='width'),
ResetTool(),
HoverTool(tooltips=[tooltip(name) for name in tooltip_names], names=['with_hover'])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny, x_axis_type='datetime', tools=tools)
f.yaxis.axis_label = f'lines - {N.ACTIVE_TIME_H}'
f.y_range = time_y_range
f.extra_y_ranges = {N.ACTIVE_DISTANCE: distance_y_range}
f.add_layout(LinearAxis(y_range_name=N.ACTIVE_DISTANCE, axis_label=f'dots - {N.ACTIVE_DISTANCE_KM}'), 'right')
plotter = comb_plotter()
for time, colour, group in zip(times, colours, groups):
time_h = N._slash(time, U.H)
source[time_h] = source[time] / 3600
source[N.ACTIVITY_GROUP] = group
plotter(f, x=N.TIME, y=time_h, source=source, color=colour, alpha=1)
plotter = dot_plotter()
for distance, colour, group in zip(distances, colours, groups):
distance_km = N._slash(distance, U.KM)
source[distance_km] = source[distance]
source[N.ACTIVITY_GROUP] = group
plotter(f, x=N.TIME, y=distance_km, source=source, color=colour, alpha=1, name='with_hover',
y_range_name=N.ACTIVE_DISTANCE)
f.xaxis.axis_label = N.TIME
f.toolbar.logo = None
if ny < 300: f.toolbar_location = None
if x_range: f.x_range = x_range
return f
0
View Source File : line.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def comparison_line_plot(nx, ny, x, y, source, other=None, ylo=None, yhi=None, x_range=None,
output_backend=DEFAULT_BACKEND):
if not present(source, x, y): return None
tools = [PanTool(dimensions='width'),
ZoomInTool(dimensions='width'), ZoomOutTool(dimensions='width'),
ResetTool(),
HoverTool(tooltips=[tooltip(x)
for x in (y, N.DISTANCE_KM, N.LOCAL_TIME)], names=['with_hover'])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny,
x_axis_type='datetime' if N.TIME in x else 'linear', tools=tools)
f.y_range = make_range(source[y], lo=ylo, hi=yhi) # was this ignored previously?
add_tsid_line(f, x, y, source)
if present(other, y):
add_tsid_line(f, x, y, other, color='grey')
diff = subtract(source, other, x, y)
green, red, y_range2 = patches(x, y, diff)
f.extra_y_ranges = {'delta': y_range2}
f.patch(x=green.index, y=green, color='green', alpha=0.1, y_range_name='delta')
f.patch(x=red.index, y=red, color='red', alpha=0.1, y_range_name='delta')
f.yaxis.axis_label = y
f.xaxis.axis_label = x
f.toolbar.logo = None
if x_range: f.x_range = x_range
return f
def add_hr_zones(f, df, x, hr_zones):
0
View Source File : line.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def map_intensity(nx, ny, source, z, power=1.0, color='red', alpha=0.01, ranges=None, output_backend=MAP_BACKEND):
if not present(source, z): return None
tools = [PanTool(dimensions='both'),
ZoomInTool(dimensions='both'), ZoomOutTool(dimensions='both'),
ResetTool(),
HoverTool(tooltips=[tooltip(x) for x in (z, N.DISTANCE_KM, N.LOCAL_TIME)])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny,
x_axis_type='mercator', y_axis_type='mercator', title=z, match_aspect=True, tools=tools)
tools[-1].renderers = [add_route(f, source)]
mn, mx = source[z].min(), source[z].max()
source['size'] = sqrt(nx * ny) * ((source[z] - mn) / (mx - mn)) ** power / 10
f.circle(x=N.SPHERICAL_MERCATOR_X, y=N.SPHERICAL_MERCATOR_Y, size='size', source=source, color=color, alpha=alpha)
f.axis.visible = False
f.toolbar.logo = None
if ranges is not None:
f.x_range = ranges.x_range
f.y_range = ranges.y_range
return f
def map_intensity_signed(nx, ny, source, z, power=1.0, color='red', color_neg='blue', alpha=0.01, ranges=None,
0
View Source File : line.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def map_intensity_signed(nx, ny, source, z, power=1.0, color='red', color_neg='blue', alpha=0.01, ranges=None,
output_backend=MAP_BACKEND):
if not present(source, z): return None
tools = [PanTool(dimensions='both'),
ZoomInTool(dimensions='both'), ZoomOutTool(dimensions='both'),
ResetTool(),
HoverTool(tooltips=[tooltip(x) for x in (z, N.DISTANCE_KM, N.LOCAL_TIME)])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny,
x_axis_type='mercator', y_axis_type='mercator', title=z, match_aspect=True, tools=tools)
tools[-1].renderers = [add_route(f, source)]
mn, mx = source[z].min(), source[z].max()
scale = max(mx, -mn)
if mx > 0:
source['size'] = np.sign(source[z]) * sqrt(nx * ny) * (np.abs(source[z]) / scale) ** power / 10
source['size'].clip(lower=0, inplace=True)
f.circle(x=N.SPHERICAL_MERCATOR_X, y=N.SPHERICAL_MERCATOR_Y, size='size', source=source,
color=color, alpha=alpha)
if mn < 0:
source['size'] = -np.sign(source[z]) * sqrt(nx * ny) * (np.abs(source[z]) / scale) ** power / 10
source['size'].clip(lower=0, inplace=True)
f.circle(x=N.SPHERICAL_MERCATOR_X, y=N.SPHERICAL_MERCATOR_Y, size='size', source=source,
color=color_neg, alpha=alpha)
f.axis.visible = False
f.toolbar.logo = None
if ranges is not None:
f.x_range = ranges.x_range
f.y_range = ranges.y_range
return f
def map_thumbnail(nx, ny, source, sample='1min', caption=True, title=True, output_backend=MAP_BACKEND):
0
View Source File : line.py
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
License : GNU Affero General Public License v3.0
Project Creator : andrewcooke
def multi_plot(nx, ny, x, ys, source, colors, alphas=None, x_range=None, y_label=None, rescale=False,
plotters=None, output_backend=DEFAULT_BACKEND):
if not ys or not present(source, x, *ys): return None
tools = [PanTool(dimensions='width'),
ZoomInTool(dimensions='width'), ZoomOutTool(dimensions='width'),
ResetTool(),
HoverTool(tooltips=[tooltip(x) for x in ys + [N.LOCAL_TIME]], names=['with_hover'])]
f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny,
x_axis_type='datetime' if N.TIME in x else 'linear', tools=tools)
if y_label:
f.yaxis.axis_label = y_label
elif rescale:
f.yaxis.axis_label = ys[0]
else:
f.yaxis.axis_label = ', '.join(ys)
if rescale: f.extra_y_ranges = {}
if alphas is None: alphas = [1 for _ in ys]
while len(plotters) < len(ys): plotters += plotters
for y, color, alpha, plotter in zip(ys, colors, alphas, plotters):
y_range = make_range(source[y])
if rescale and y != ys[0]:
f.extra_y_ranges[y] = y_range
f.add_layout(LinearAxis(y_range_name=y, axis_label=y), 'right')
plotter(f, x=x, y=y, source=source, color=color, alpha=alpha, y_range_name=y, name='with_hover')
else:
f.y_range = y_range
plotter(f, x=x, y=y, source=source, color=color, alpha=alpha, name='with_hover')
f.xaxis.axis_label = x
f.toolbar.logo = None
if ny < 300: f.toolbar_location = None
if x_range: f.x_range = x_range
return f
def add_multi_line_at_index(f, x, ys, source, colors, alphas=None, dash='dotted', index=-1):
0
View Source File : draw.py
License : Apache License 2.0
Project Creator : aws
License : Apache License 2.0
Project Creator : aws
def draw(S, position=None, with_labels=False):
"""Plot the given signed social network.
Args:
S: The network
position (dict, optional):
The position for the nodes. If no position is provided, a layout will be calculated. If the nodes have
'color' attributes, a Kamanda-Kawai layout will be used to group nodes of the same color together.
Otherwise, a circular layout will be used.
Returns:
A dictionary of positions keyed by node.
Examples:
>>> import dwave_structural_imbalance_demo as sbdemo
>>> gssn = sbdemo.GlobalSignedSocialNetwork()
>>> nld_before = gssn.get_node_link_data('Syria', 2013)
>>> nld_after = gssn.solve_structural_imbalance('Syria', 2013)
# draw Global graph before solving; save node layout for reuse
>>> position = sbdemo.draw('syria.png', nld_before)
# draw the Global graph; reusing the above layout, and calculating a new grouped layout
>>> sbdemo.draw('syria_imbalance.png', nld_after, position)
>>> sbdemo.draw('syria_imbalance_grouped', nld_after)
"""
# we need a consistent ordering of the edges
edgelist = S.edges()
nodelist = S.nodes()
def layout_wrapper(S):
pos = position
if pos is None:
try:
# group bipartition if nodes are colored
dist = defaultdict(dict)
for u, v in product(nodelist, repeat=2):
if u == v: # node has no distance from itself
dist[u][v] = 0
elif (
nodelist[u]["color"] == nodelist[v]["color"]
): # make same color nodes closer together
dist[u][v] = 1
else: # make different color nodes further apart
dist[u][v] = 2
pos = nx.kamada_kawai_layout(S, dist)
except KeyError:
# default to circular layout if nodes aren't colored
pos = nx.circular_layout(S)
return pos
# call layout wrapper once with all nodes to store position for calls with partial graph
position = layout_wrapper(S)
plot = Plot(
plot_width=600, plot_height=400, x_range=Range1d(-1.2, 1.2), y_range=Range1d(-1.2, 1.2)
)
tools = [WheelZoomTool(), ZoomInTool(), ZoomOutTool(), PanTool()]
plot.add_tools(*tools)
plot.toolbar.active_scroll = tools[0]
def get_graph_renderer(S, line_dash):
# we need a consistent ordering of the edges
edgelist = S.edges()
nodelist = S.nodes()
# get the colors assigned to each edge based on friendly/hostile
sign_edge_color = ["#87DACD" if S[u][v]["sign"] == 1 else "#FC9291" for u, v in edgelist]
# get the colors assigned to each node by coloring
try:
coloring_node_color = [
"#4378F8" if nodelist[v]["color"] else "#FFE897" for v in nodelist
]
except KeyError:
coloring_node_color = ["#FFFFFF" for __ in nodelist]
graph_renderer = from_networkx(S, layout_wrapper)
circle_size = 10
graph_renderer.node_renderer.data_source.add(coloring_node_color, "color")
graph_renderer.node_renderer.glyph = Circle(size=circle_size, fill_color="color")
edge_size = 2
graph_renderer.edge_renderer.data_source.add(sign_edge_color, "color")
try:
graph_renderer.edge_renderer.data_source.add(
[S[u][v]["event_year"] for u, v in edgelist], "event_year"
)
graph_renderer.edge_renderer.data_source.add(
[S[u][v]["event_description"] for u, v in edgelist], "event_description"
)
plot.add_tools(
HoverTool(
tooltips=[("Year", "@event_year"), ("Description", "@event_description")],
line_policy="interp",
)
)
except KeyError:
pass
graph_renderer.edge_renderer.glyph = MultiLine(line_color="color", line_dash=line_dash)
graph_renderer.inspection_policy = EdgesAndLinkedNodes()
return graph_renderer
try:
S_dash = S.edge_subgraph(((u, v) for u, v in edgelist if S[u][v]["frustrated"]))
S_solid = S.edge_subgraph(((u, v) for u, v in edgelist if not S[u][v]["frustrated"]))
plot.renderers.append(get_graph_renderer(S_dash, "dashed"))
plot.renderers.append(get_graph_renderer(S_solid, "solid"))
except KeyError:
plot.renderers.append(get_graph_renderer(S, "solid"))
plot.background_fill_color = "#202239"
positions = layout_wrapper(S)
if with_labels:
data = {"xpos": [], "ypos": [], "label": []}
for label, pos in positions.items():
data["label"].append(label)
data["xpos"].append(pos[0])
data["ypos"].append(pos[1])
labels = LabelSet(
x="xpos",
y="ypos",
text="label",
level="glyph",
source=ColumnDataSource(data),
x_offset=-5,
y_offset=10,
text_color="#F5F7FB",
text_font_size="12pt",
)
plot.add_layout(labels)
show(Row(plot))
return positions
0
View Source File : test_objects.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def large_plot(n):
from bokeh.models import (
Plot, LinearAxis, Grid, GlyphRenderer,
ColumnDataSource, DataRange1d, PanTool, ZoomInTool, ZoomOutTool, WheelZoomTool, BoxZoomTool,
BoxSelectTool, SaveTool, ResetTool
)
from bokeh.models.layouts import Column
from bokeh.models.glyphs import Line
col = Column()
objects = set([col])
for i in xrange(n):
source = ColumnDataSource(data=dict(x=[0, i + 1], y=[0, i + 1]))
xdr = DataRange1d()
ydr = DataRange1d()
plot = Plot(x_range=xdr, y_range=ydr)
xaxis = LinearAxis()
plot.add_layout(xaxis, "below")
yaxis = LinearAxis()
plot.add_layout(yaxis, "left")
xgrid = Grid(dimension=0)
plot.add_layout(xgrid, "center")
ygrid = Grid(dimension=1)
plot.add_layout(ygrid, "center")
tickers = [xaxis.ticker, xaxis.formatter, yaxis.ticker, yaxis.formatter]
glyph = Line(x='x', y='y')
renderer = GlyphRenderer(data_source=source, glyph=glyph)
plot.renderers.append(renderer)
pan = PanTool()
zoom_in = ZoomInTool()
zoom_out = ZoomOutTool()
wheel_zoom = WheelZoomTool()
box_zoom = BoxZoomTool()
box_select = BoxSelectTool()
save = SaveTool()
reset = ResetTool()
tools = [pan, zoom_in, zoom_out, wheel_zoom, box_zoom, box_select, save, reset]
plot.add_tools(*tools)
col.children.append(plot)
objects |= set([
xdr, ydr,
xaxis, yaxis,
xgrid, ygrid,
renderer, renderer.view, glyph,
source, source.selected, source.selection_policy,
plot, plot.x_scale, plot.y_scale, plot.toolbar, plot.title,
box_zoom.overlay, box_select.overlay,
] + tickers + tools)
return col, objects
class TestMetaModel(object):