Plot Streams

This page describes ways to generate dynamic plots of streams. The plotting software uses bokeh. See for a description of bokeh, its license, and how to download it. 

The plots described here require that you set up a bokeh server by calling:

bokeh serve

from the command line.

The simplest, and the most frequently used, case is that of plotting a single stream on a single figure. The plot is dynamic because the curve moves as new values are added to the data stream. This simplest case is described in the section: Plot a single stream. In some cases, you may want to plot multiple streams on a single figure; this is addressed in the section: Plot multiple streams. Plots of multiple figures, where each figure may have multiple streams is addressed in the section: Plot multiple figures.

Plot a Single Stream

    in_stream, max_arrival_rate=1000, plot_interval_time=1,
    num_steps = None, rollover_percent=100,
    y_axis_label = 'y', point_color='blue', point_size=10,
    plot_width=600, plot_height=600,
    plot_title="Stream over Time")

in_stream is the stream that is plotted. in_stream is the only required parameter in a call to plot_stream; all the other parameters are optional.

max_arrival_rate is the maximum rate at which new elements are added to in_stream, where the rate is measured in elements per second.

The plot is updated every plot_interval_time seconds.

You typically want to plot the stream for ever; however, for debugging you may want to plot the stream a limited number of times. If num_steps is a number then the plot terminates after num_steps number of updates to the plot. If num_steps is None, then the plot continues forever.

rollover_percent is the percent of the plot that is rolled over from one update to the next.

point_color and point_size refer to the color and size of each point in the curve in the plot. y_axis_labelplot_width, plot_height, and plot_title refer to the label of the y axis and the width and height and title of the plot. For example if x is a stream of sine values with a wavelength of 32 then:


shows a dynamically changing sine wave, a snapshot of which is shown below.

Screen Shot 2017-05-01 at 10.50.02 AM.png

Plot Multiple Streams

You can plot multiple streams on the same figure. In this case you specify a list of colors for each stream in the figure and you can also specify the legends (names) of the curves. The other attributes, such as the size and width of the plot, are the same as those for plotting a single stream, and are not described here.

  in_stream, curve_colors, curve_legends=None,, .....)

in_stream is a single stream that merges the streams that are to be plotted. In the following each of the streams that are merged are called component streams of the merged stream.

curve_colors is a list of strings where each string is a color such as 'black' and the i-th color is the color of the curve of the i-th component stream. 

curve_legends is a list of strings where the i-th string is the name given to the curve of the i-th component stream. 

For example if x and y are streams of sine and cosine values with a wavelength of 32 then:

   in_stream=zip_stream([x, y]),
   curve_colors=['red', 'blue'],
   curve_legends=['sine', 'cosine'])

shows a dynamically changing sine and cosine waves colored red and blue, respectively, with the legends 'sine' and 'cosine', respectively.

Plot multiple figures

When you want to plot multiple figures, where each figure plots one or more streams, and where all figures are updated dynamically, use:

    in_stream, curve_colors, stream_ids_in_figures,
    curve_legends=None, figure_titles=None, ...

in_stream, curve_colors, and curve_legends are exactly as for the case of plot multiple streams. stream_ids_in_figures identifies the streams that are plotted in each figure. stream_ids_in_figures is a list of lists, where stream_ids_in_figures[i] is the list of indices of streams that are plotted in the i-th figure. Likewise, figure_titles is a list of strings where figure_titles[i] is the title of the i-th figure.

The figures are plotted one below the other. The time-axis, the stream colors, and the stream legends shown on the plots are the same for all the figures.

            [sine_stream, cosine_stream, sawtooth_stream]),
        curve_colors=['red', 'blue', 'black'],
        curve_legends=['sine', 'cosine', 'sawtooth'],
        figure_titles=['sine_cosine', 'cosine_sawtooth'])

This code plots two figures that are updated dynamically. The list of indices of the streams plotted in the first figure is [0, 1], and for the second figure is [1, 2]. So, the first figure plots sine_stream and cosine_stream, while the second figure plots cosine_stream and sawtooth_stream. The title of the first figure is 'sine_cosine' and that of the second is 'cosine_sawtooth'.

A snapshot of the dynamic plot generated by this figure is shown: