예제 #1
0
    def fetch_mpl_obj(self):
        group = "Gas Concentration vs Time"
        plot = dict(aspect=2)
        legend = dict(legend_position='best', aspect=2)
        graph = None

        options = hv.Store.options(backend='matplotlib')
        options.Curve = hv.Options('style',
                                   color=hv.Cycle(values=self.gases.values()),
                                   linewidth=2)

        for data in self.graph_data:
            graph_inter = hv.Curve(data['data'],
                                   vdims=['Gas Concentration'],
                                   kdims=['Time'],
                                   label=data['label'],
                                   group=group)
            if graph:
                graph *= graph_inter
            else:
                graph = graph_inter
        for data in self.text_labels:
            graph *= hv.Text(data['key'],
                             data['value'],
                             data['date'],
                             fontsize=10)

        opts = {'Curve': {'plot': plot}, 'Overlay': {'plot': legend}}
        self.mpl_obj = graph(opts) if graph else None
예제 #2
0
def gen_sankey_plot(nodes, edges, title_text='Sankey Chart'):
    options = hv.Store.options('bokeh')
    options.Sankey = hv.Options(
        'style',
        node_line_alpha=0,
        node_nonselection_alpha=0.2,
        node_size=10,
        node_line_width=0,
        edge_cmap=['#002F6C', '#BA0C2F', '#A7C6ED', '#212721'],
        cmap=['#002F6C', '#BA0C2F', '#212721', '#212721'],
        edge_nonselection_alpha=0.2,
        edge_line_alpha=0,
        edge_fill_alpha=0.7,
        edge_hover_alpha=1,
        edge_hover_color='#002F6C',
        label_text_font_size='8pt')

    sankey = hv.Sankey((edges, nodes),
                       ['From', 'To']).options(label_index='label',
                                               label_position='left',
                                               width=800,
                                               height=800,
                                               edge_color_index='To')
    # pass to bokeh for further changes
    renderer = hv.renderer('bokeh')
    plot = renderer.get_plot(sankey, doc=curdoc()).state

    # return plot
    return plot
def modify_doc(doc):
    options = hv.Store.options(backend='bokeh')
    options.Points = hv.Options(
        'plot',
        width=800,
        height=600,
        size_index=None,
    )
    options.Points = hv.Options('style', cmap='rainbow', line_color='black')

    def create_figure():
        label = "%s vs %s" % (x.value.title(), y.value.title())
        kdims = [x.value, y.value]
        opts, style = {}, {}
        opts['color_index'] = color.value if color.value != 'None' else None
        if size.value != 'None':
            opts['size_index'] = size.value
            opts['scaling_factor'] = (1. / df[size.value].max()) * 200
        points = hv.Points(df, kdims=kdims, label=label).opts(plot=opts,
                                                              style=style)
        return renderer.get_plot(points).state

    def update(attr, old, new):
        layout.children[1] = create_figure()

    x = Select(title='X-Axis', value='mpg', options=quantileable)
    x.on_change('value', update)

    y = Select(title='Y-Axis', value='hp', options=quantileable)
    y.on_change('value', update)

    size = Select(title='Size', value='None', options=['None'] + quantileable)
    size.on_change('value', update)

    color = Select(title='Color',
                   value='None',
                   options=['None'] + quantileable)
    color.on_change('value', update)

    controls = widgetbox([x, y, color, size], width=200)
    layout = row(controls, create_figure())

    doc.add_root(layout)
    return doc
예제 #4
0
"""
Example app demonstrating how to use the HoloViews API to generate
a bokeh app with complex interactivity. Uses a Selection1D stream
to compute the mean y-value of the current selection.
"""

import numpy as np
import holoviews as hv
import holoviews.plotting.bokeh  # noqa (Activate backend)
from holoviews.streams import Selection1D

renderer = hv.Store.renderers['bokeh']
hv.Store.options(backend='bokeh').Points = hv.Options('plot',
                                                      tools=['box_select'])

data = np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000, ))
points = hv.Points(data)
sel = Selection1D(source=points)
mean_sel = hv.DynamicMap(lambda index: hv.HLine(points['y'][index].mean()
                                                if index else -10),
                         kdims=[],
                         streams=[sel])

doc = renderer.app((points * mean_sel))
doc.title = 'HoloViews Selection Stream'
예제 #5
0
import holoviews as hv
import numpy as np
import dask
import datashader as ds
from datashader.bokeh_ext import InteractiveImage

SIZING_MODE = 'fixed'  # 'scale_width' also looks nice with this example

desc = Div(text=open(join(dirname(__file__), "description.html")).read(),
           width=800)

renderer = hv.renderer('bokeh')
options = hv.Store.options(backend='bokeh')
options.Points = hv.Options(
    'plot',
    width=800,
    height=600,
    size_index=None,
)
options.Points = hv.Options('style', cmap='rainbow', line_color='black')


def update(attr, old, new):
    lay.children[1] = create_figure()


def create_figure():
    label = "%s vs %s" % (x.value.title(), y.value.title())
    kdims = [x.value, y.value]

    opts, style = {}, {}
    opts['color_index'] = color.value if color.value != 'None' else None
예제 #6
0
 def setOption(self, option):
     options = hv.Options(option)
     return self.opts(options)