Skip to content

Commit

Permalink
Updated apps
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 21, 2018
1 parent 1576731 commit ef5e0eb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 54 deletions.
14 changes: 6 additions & 8 deletions examples/gallery/apps/bokeh/game_of_life.py
@@ -1,6 +1,7 @@
import numpy as np
import holoviews as hv

from holoviews import opts
from holoviews.streams import Tap, Counter
from scipy.signal import convolve2d

Expand Down Expand Up @@ -56,26 +57,23 @@ def step(X):
return (nbrs_count == 3) | (X & (nbrs_count == 2))

def update(pattern, counter, x, y):
if counter:
img.data = step(img.data)
if x and y:
pattern = np.array(shapes[pattern])
r, c = pattern.shape
y, x = img.sheet2matrixidx(x,y)
img.data[y:y+r,x:x+c] = pattern[::-1]
else:
img.data = step(img.data)
return hv.Image(img)

title = 'Game of Life - Tap to place pattern, Doubletap to clear'
opts = {
'style': {'cmap': 'gray', 'toolbar': False, },
'plot' : {'height': 400, 'width': 800, 'title': '{label}',
'xaxis': None, 'yaxis': None}
}
img_opts = opts.Image(cmap='gray', toolbar=None, height=400, width=800,
title=title, xaxis=None, yaxis=None)
img = hv.Image(np.zeros((100, 200), dtype=np.uint8))
counter, tap = Counter(transient=True), Tap(transient=True)
pattern_dim = hv.Dimension('Pattern', values=sorted(shapes.keys()))
dmap = hv.DynamicMap(update, kdims=[pattern_dim], streams=[counter, tap])

doc = renderer.server_doc(dmap.redim.range(z=(0, 1)).opts(**opts))
doc = renderer.server_doc(dmap.redim.range(z=(0, 1)).opts(img_opts))
dmap.periodic(0.05, None)
doc.title = 'Game of Life'
19 changes: 11 additions & 8 deletions examples/gallery/apps/bokeh/gapminder.py
Expand Up @@ -11,7 +11,9 @@
from bokeh.layouts import layout
from bokeh.models import Slider, Button
from bokeh.sampledata import gapminder
from holoviews.plotting.bokeh import BokehRenderer
from holoviews import dim, opts

renderer = hv.renderer('bokeh')

# Declare dataset
panel = pd.Panel({'Fertility': gapminder.fertility,
Expand Down Expand Up @@ -41,13 +43,13 @@
for yr in gapminder_ds.keys()})

# Define options
opts = {'plot': dict(width=1000, height=600,tools=['hover'], size_index='Population',
color_index='Group', size_fn=np.sqrt, title="{label}"),
'style': dict(cmap='Set1', size=0.3, line_color='black', alpha=0.6)}
text_opts = {'style': dict(text_font_size='52pt', text_color='lightgray')}

# Combine Points and Text
hvgapminder = (gapminder_ds({'Points': opts}) * text({'Text': text_opts})).relabel('Gapminder Demo')
hvgapminder = (gapminder_ds * text).opts(
opts.Points(alpha=0.6, color='Group', cmap='Set1', line_color='black',
size=np.sqrt(dim('Population'))*0.005, width=1000, height=600,
tools=['hover'], title='Gapminder Demo'),
opts.Text(text_font_size='52pt', text_color='lightgray'))


# Define custom widgets
def animate_update():
Expand Down Expand Up @@ -80,7 +82,8 @@ def animate():

# Get HoloViews plot and attach document
doc = curdoc()
hvplot = BokehRenderer.get_plot(hvgapminder, doc)
hvplot = renderer.get_plot(hvgapminder, doc)
hvplot.update((1964,))

# Make a bokeh layout and add it as the Document root
plot = layout([[hvplot.state], [slider, button]], sizing_mode='fixed')
Expand Down
23 changes: 9 additions & 14 deletions examples/gallery/apps/bokeh/mandelbrot.py
Expand Up @@ -7,11 +7,12 @@
import numpy as np
import holoviews as hv

from holoviews import Options
from holoviews.plotting.bokeh import BokehRenderer
from holoviews import opts
from holoviews.streams import RangeXY
from numba import jit

renderer = hv.renderer('bokeh')

@jit
def mandel(x, y, max_iters):
"""
Expand Down Expand Up @@ -59,17 +60,11 @@ def get_fractal(x_range, y_range):
dmap = hv.DynamicMap(get_fractal, label='Manderbrot Explorer',
streams=[range_stream]).hist(log=True)

# Define styling options
options = hv.Store.options('bokeh')
options.Image = {
'style': Options(cmap='fire'),
'plot' : Options(logz=True, height=600, width=600,
xaxis=None, yaxis=None)
}
options.Histogram = {
'norm': Options(framewise=True),
'plot': Options(logy=True, width=200)
}
# Apply options
dmap.opts(
opts.Histogram(framewise=True, logy=True, width=200),
opts.Image(cmap='fire', logz=True, height=600, width=600,
xaxis=None, yaxis=None))

doc = BokehRenderer.server_doc(dmap)
doc = renderer.server_doc(dmap)
doc.title = 'Mandelbrot Explorer'
34 changes: 20 additions & 14 deletions examples/gallery/apps/bokeh/nytaxi_hover.py
Expand Up @@ -2,12 +2,13 @@
Bokeh app example using datashader for rasterizing a large dataset and
geoviews for reprojecting coordinate systems.
This example requires the 1.7GB nyc_taxi.csv dataset which you can
obtain by following the instructions for 'nyc_taxi' at:
This example requires the 1.7GB nyc_taxi_wide.parquet dataset which
you can obtain by downloading the file from AWS:
https://github.com/bokeh/datashader/blob/master/examples/README.md
https://s3.amazonaws.com/datashader-data/nyc_taxi_wide.parq
Once this CSV is placed in a data/ subfolder, you can run this app with:
Once this parquet is placed in a data/ subfolder, you can run this app
with:
bokeh serve --show nytaxi_hover.py
Expand All @@ -16,18 +17,23 @@
import holoviews as hv
import dask.dataframe as dd

from holoviews import opts
from holoviews.operation.datashader import aggregate

hv.extension('bokeh')
renderer = hv.renderer('bokeh')

# Set plot and style options
hv.util.opts('Image [width=800 height=400 shared_axes=False logz=True xaxis=None yaxis=None] {+axiswise} ')
hv.util.opts("HLine VLine (color='white' line_width=1) Layout [shared_axes=False] ")
hv.util.opts("Curve [xaxis=None yaxis=None show_grid=False, show_frame=False] (color='orangered') {+framewise}")

# Read the CSV file
df = dd.read_parquet('/Users/philippjfr/development/pyviz/data/nyc_taxi_50k.parq')
df = df.persist()
opts.defaults(
opts.Curve(xaxis=None, yaxis=None, show_grid=False, show_frame=False,
color='orangered', framewise=True, width=100),
opts.Image(width=800, height=400, shared_axes=False, logz=True,
xaxis=None, yaxis=None, axiswise=True),
opts.HLine(color='white', line_width=1),
opts.Layout(shared_axes=False),
opts.VLine(color='white', line_width=1))

# Read the parquet file
df = dd.read_parquet('./data/nyc_taxi_wide.parq').persist()

# Declare points
points = hv.Points(df, kdims=['pickup_x', 'pickup_y'], vdims=[])
Expand All @@ -42,8 +48,8 @@
sampled = hv.util.Dynamic(agg, operation=lambda obj, x: obj.sample(pickup_x=x),
streams=[pointerx], link_inputs=False)

hvobj = ((agg * hline * vline) << sampled.opts(plot={'Curve': dict(width=100)}))
hvobj = ((agg * hline * vline) << sampled)

# Obtain Bokeh document and set the title
doc = hv.renderer('bokeh').server_doc(hvobj)
doc = renderer.server_doc(hvobj)
doc.title = 'NYC Taxi Crosshair'
16 changes: 7 additions & 9 deletions examples/gallery/apps/bokeh/streaming_psutil.py
Expand Up @@ -3,8 +3,9 @@
import psutil
import pandas as pd
import holoviews as hv
from holoviews import dim, opts

hv.extension('bokeh')
renderer = hv.renderer('bokeh')

# Define functions to get memory and CPU usage
def get_mem_data():
Expand Down Expand Up @@ -48,15 +49,12 @@ def cb():
cpu_dmap = hv.DynamicMap(cpu_box, streams=[cpu_stream])
mem_dmap = hv.DynamicMap(mem_stack, streams=[mem_stream])

cpu_opts = {'plot': dict(width=500, height=400, color_index='CPU'),
'style': dict(box_fill_color=hv.Cycle('Category20'))}
mem_opts = dict(height=400, width=400)

plot = (cpu_dmap.redim.range(Utilization=(0, 100)).opts(**cpu_opts) +
mem_dmap.redim.range(Usage=(0, 100)).opts(plot=mem_opts))

plot = (cpu_dmap + mem_dmap).opts(
opts.Area(height=400, width=400, ylim=(0, 100)),
opts.BoxWhisker(box_fill_color=dim('CPU').str(), cmap='Category20',
width=500, height=400, ylim=(0, 100)))

# Render plot and attach periodic callback

doc = hv.renderer('bokeh').server_doc(plot)
doc = renderer.server_doc(plot)
doc.add_periodic_callback(cb, 0.05)
2 changes: 1 addition & 1 deletion examples/user_guide/Plots_and_Renderers.ipynb
Expand Up @@ -125,7 +125,7 @@
" # The handles contain common plot objects\n",
" plot.handles\n",
"\n",
"curve = curve.options(hooks=[hook])"
"curve = curve.opts(hooks=[hook])"
]
},
{
Expand Down

0 comments on commit ef5e0eb

Please sign in to comment.