Created
March 13, 2018 10:46
-
-
Save LEMUEGGE/4a62a677e33e2cb16e62abfd686f9cea to your computer and use it in GitHub Desktop.
MRE holoviews + bokeh memory consumption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from bokeh.layouts import row, widgetbox | |
from bokeh.models.widgets import TextInput | |
import holoviews as hv | |
from bokeh.plotting import figure | |
class layout_object(object): | |
def __init__(self): | |
print("layout instance initialized") | |
#contains holoviews dynamic maps | |
self.webpage_layout = [] | |
#contains bokeh plots and controller | |
self.webpage = [] | |
self.stream = hv.streams.RangeXY(x_range=None,y_range=None,transient=True) | |
def create_layout_holoviews(self): | |
# initialize renderer that transforms holoviews objects into bokeh plots | |
renderer = hv.renderer('bokeh').instance(mode='server') | |
for obj in self.webpage_layout: | |
if obj.controller is not None: | |
# if controller exist, create 2 column view | |
self.webpage.append([renderer.get_plot(obj.plot_container).state,obj.controller]) | |
def create_layout_bokeh(self): | |
for obj in self.webpage_layout: | |
if obj.controller is not None: | |
self.webpage.append([obj.bokeh_plot,obj.controller]) | |
def __del__(self): | |
print("layout instance deleted") | |
class plot_object(object): | |
def __init__(self, layout_obj): | |
print("plot instance initialized") | |
layout_obj.webpage_layout.append(self) | |
self.stream = layout_obj.stream | |
self.controller = widgetbox(TextInput(value="controller", title="Test controller", | |
)) | |
self.bokeh_plot = figure(title="simple line example", x_axis_label='x', y_axis_label='y') | |
# add a line renderer with legend and line thickness | |
self.bokeh_plot.line([1,2], [3,4], line_width=2) | |
def __del__(self): | |
print("plot instance deleted") | |
def plot(self,x_range=None,y_range=None): | |
""" | |
holoviews plot for dynamicmap | |
""" | |
def rectangle(x=0, y=0, width=.05, height=.05): | |
return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)]) | |
return hv.Polygons([{('x', 'y'): rectangle(x, y), 'level': z} | |
for x, y, z in np.random.rand(100, 3)], vdims='level').redim.range(x=(-.1,1.1), y=(-0.1, 1.1)) | |
def set_up_plot_container(self): | |
self.plot_container = hv.DynamicMap(self.plot,streams=[self.stream]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Testing memory realease in Bokeh with holoviews. | |
''' | |
from bokeh.io import curdoc | |
from bokeh.layouts import layout | |
from external_module import layout_object, plot_object | |
layout_obj = layout_object() | |
plot_obj = plot_object(layout_obj) | |
#TEST RUN WITH HOLOVIEWS | |
plot_obj.set_up_plot_container() | |
layout_obj.create_layout_holoviews() | |
#TEST RUN WITH BOKEH | |
#layout_obj.create_layout_bokeh() | |
curdoc().add_root(layout(list(layout_obj.webpage))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment