Beispiel #1
0

# Set up StreamingDataFrame and add async callback

cpu_stream = hv.streams.Buffer(get_cpu_data(), 800, index=False)
mem_stream = hv.streams.Buffer(get_mem_data())


def cb():
    cpu_stream.send(get_cpu_data())
    mem_stream.send(get_mem_data())


# Define DynamicMaps and display plot

cpu_dmap = hv.DynamicMap(cpu_box, streams=[cpu_stream])
mem_dmap = hv.DynamicMap(mem_stack, streams=[mem_stream])

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 = renderer.server_doc(plot)
doc.add_periodic_callback(cb, 0.05)
def mem_stack(data):
    data = pd.melt(data, 'index', var_name='Type', value_name='Usage')
    areas = hv.Dataset(data).to(hv.Area, 'index', 'Usage')
    return hv.Area.stack(areas.overlay()).relabel('Memory')


def cpu_box(data):
    return hv.BoxWhisker(data, 'CPU', 'Utilization', label='CPU Usage')

# Set up StreamingDataFrame and add async callback
cpu_stream = hv.streams.Buffer(get_cpu_data(), 800, index=False)
mem_stream = hv.streams.Buffer(get_mem_data())

def cb():
    cpu_stream.send(get_cpu_data())
    mem_stream.send(get_mem_data())

# Define DynamicMaps and display plot
cpu_dmap = hv.DynamicMap(cpu_box, streams=[cpu_stream])
mem_dmap = hv.DynamicMap(mem_stack, streams=[mem_stream])

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

# Render plot and attach periodic callback
doc = renderer.server_doc(plot)
doc.add_periodic_callback(cb, 0.05)
    "Some time varying function"
    return np.exp(np.sin(xs + np.pi / time))


def integral(limit_a, limit_b, y, time):
    limit_a = -3 if limit_a is None else np.clip(limit_a, -3, 3)
    limit_b = 3 if limit_b is None else np.clip(limit_b, -3, 3)
    curve = hv.Curve((xs, function(xs, time)))
    area = hv.Area((xs, function(xs, time)))[limit_a:limit_b]
    summed = area.dimension_values('y').sum() * 0.015  # Numeric approximation
    return (area * curve * hv.VLine(limit_a) * hv.VLine(limit_b) *
            hv.Text(limit_b - 0.8, 2.0, '%.2f' % summed))


integral_streams = [
    streams.Stream.define('Time', time=1.0)(),
    streams.PointerX().rename(x='limit_b'),
    streams.Tap().rename(x='limit_a')
]

integral_dmap = hv.DynamicMap(integral, streams=integral_streams)

integral_dmap.opts(opts.Area(color='#fff8dc', line_width=2),
                   opts.Curve(color='black'), opts.VLine(color='red'))

image.dimensions()

dim('charge').min().apply(image)

dim('charge').max().apply(image)
Beispiel #4
0
clr_inSample = 'steelblue'
clr_5cv = 'tomato'
clr_20x5cv = 'gold'
clr_5cvMean = 'maroon'
clr_20x5cvMean = 'darkgoldenrod'

default_fontsizes = dict(title=8, labels=8, ticks=7, minor_ticks=7, legend=7)

fig_opts = [
    opts.Layout(aspect_weight=1,
                fig_inches=(3.42, None),
                sublabel_size=10,
                fontsize=8),
    opts.Overlay(fontsize=default_fontsizes, ),
    opts.Area(fontsize=default_fontsizes),
    opts.Arrow(textsize=default_fontsizes),
    opts.Curve(fontsize=default_fontsizes),
    opts.HexTiles(fontsize=default_fontsizes),
    opts.Histogram(fontsize=default_fontsizes),
    opts.Raster(fontsize=default_fontsizes),
    opts.Scatter(fontsize=default_fontsizes),
    opts.Text(fontsize=default_fontsizes),
    opts.QuadMesh(fontsize=default_fontsizes),
    opts.Violin(fontsize=default_fontsizes),
    opts.VLine(fontsize=default_fontsizes),
]

# hv hooks

Beispiel #5
0
    e_min = histogram.edges[0]

    limit_a = e_min if limit_a is None else np.clip(limit_a, e_min, e_max)
    limit_b = e_max if limit_b is None else np.clip(limit_b, e_min, e_max)

    area = hv.Area((curve.dimension_values('energy'),
                    curve.dimension_values('frequency')))[limit_a:limit_b]
    charge = np.sum(
        np.diff(histogram[limit_a:limit_b].edges) *
        histogram[limit_a:limit_b].values)

    return curve * area * hv.VLine(limit_a) * hv.VLine(limit_b) * hv.Text(
        limit_b - 2., 5, 'Q = %.0f pC' % charge)


integral_dmap = hv.DynamicMap(integrated_charge, streams=integral_streams)

integral_dmap.opts(
    opts.Area(color='#fff8dc', line_width=2),
    opts.Curve(color='black',
               height=300,
               responsive=True,
               show_grid=True,
               xlim=(None, e_max),
               ylim=(None, 10)), opts.VLine(color='red'))

integral_dmap.event(iteration=800)

print(time_series.iterations)