Exemplo n.º 1
0
def make_plot(xname, yname, xax=False, yax=False):
    mbl = 40 if yax else 0
    mbb = 40 if xax else 0
    plot = Plot(
        x_range=xdr, y_range=ydr, background_fill_color="#efe8e2",
        border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb,
        min_border_left=2+mbl, min_border_right=2, min_border_top=2, min_border_bottom=2+mbb)

    circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color")
    r = plot.add_glyph(source, circle)

    xdr.renderers.append(r)
    ydr.renderers.append(r)

    xticker = BasicTicker()
    if xax:
        xaxis = LinearAxis()
        xaxis.axis_label = xname
        plot.add_layout(xaxis, 'below')
        xticker = xaxis.ticker
    plot.add_layout(Grid(dimension=0, ticker=xticker))

    yticker = BasicTicker()
    if yax:
        yaxis = LinearAxis()
        yaxis.axis_label = yname
        yaxis.major_label_orientation = 'vertical'
        plot.add_layout(yaxis, 'left')
        yticker = yaxis.ticker
    plot.add_layout(Grid(dimension=1, ticker=yticker))

    plot.add_tools(PanTool(), WheelZoomTool())

    return plot
Exemplo n.º 2
0
 def add_axes(self, plot, label):
   xaxis = LinearAxis()
   yaxis = LinearAxis()      
   yaxis.axis_label = label
   plot.add_layout(xaxis, 'below')        
   plot.add_layout(yaxis, 'left')
   plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
   plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
   return plot
Exemplo n.º 3
0
def jobtype_builder():
    jtypes = ["Half Time", "Full Time", "Hourly", "Temporary"]
    xdr = FactorRange(factors=jtypes)
    ydr = DataRange1d(sources=[source_jobtype.columns("data_range")])
    plot = Plot(title="Job Type", data_sources=[source_jobtype],
                x_range=xdr, y_range=ydr, plot_width=760, plot_height=500)
    xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    yaxis.major_tick_in = 0
    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
    quad = Rect(x="jobtypes", y="jobtype_half",
                height="count", width=0.9,
                fill_color="#33A6A4")
    bars = Glyph(data_source=source_jobtype, xdata_range=xdr,
                 ydata_range=ydr, glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#686975'
    return plot
Exemplo n.º 4
0
def weekday_builder():
    dow = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
           "Saturday", "Sunday"]
    xdr = FactorRange(factors=dow)
    ydr = DataRange1d(sources=[source_dow.columns("data_range")])
    plot = Plot(title="Weekday of Job Posting", data_sources=[source_dow],
                x_range=xdr, y_range=ydr, plot_width=760, plot_height=500)
    xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    yaxis.major_tick_in = 0
    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
    quad = Rect(x="weekday", y="weekday_half",
                height="count", width=0.9,
                fill_color="#D9301A")
    bars = Glyph(data_source=source_dow, xdata_range=xdr,
                 ydata_range=ydr, glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#686975'
    return plot
Exemplo n.º 5
0
def job_loc_plot_builder():
    xdr = FactorRange(factors=countries)
    ydr = DataRange1d(sources=[source_country.columns("data_range")])

    plot = Plot(title="Postings by Job Location (Country)",
                data_sources=[source_country],
                x_range=xdr, y_range=ydr, plot_width=760, plot_height=500)

    xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)

    yaxis.major_tick_in = 0

    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)

    quad = Rect(x="country", y="count_half",
                height="count", width=0.9,
                fill_color="#483D8B")
    bars = Glyph(data_source=source_country, xdata_range=xdr,
                 ydata_range=ydr, glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#333333'
    return plot
Exemplo n.º 6
0
source = ColumnDataSource(results)

# Create a new plot and add a renderer
top = Figure(tools=tools, title=None, x_range=day_range,
             **figure_style_kws)
top.line('day', 'S', source=source,
         line_color=colors[0], line_width=3, line_cap='round')
top.y_range = Range1d(0., 40.)
top.yaxis.axis_label = "Salinity (g/kg)"
top.xaxis.axis_label_text_font_size = label_fontsize
top.yaxis.axis_label_text_font_size = label_fontsize

# overlay volume level chart to salinity
tc = "MediumBlue"  # tide color
tide_range = Range1d(start=0, end=15)
tide_axis = LinearAxis(y_range_name="Z")
tide_axis.axis_label = "Tidal Height (m)"
tide_axis.axis_label_text_color = tc
tide_axis.axis_label_text_font_size = label_fontsize
tide_axis.major_tick_line_color = tc
tide_axis.major_label_text_color = tc
tide_axis.minor_tick_line_alpha = 0.

top.extra_y_ranges = {"Z": tide_range}
# top.line('day', 'Z', source=source,
         # line_color=tc, line_width=2, line_cap='round')
top.add_layout(tide_axis, "right")
top.line('day', 'Z', source=source,
         line_color=tc, line_width=2, line_cap='round',
         y_range_name="Z")
Exemplo n.º 7
0
r = (cos(x)+1) * 6 + 6

source = ColumnDataSource(data=dict(x=x, y=y, r=r))

xdr = DataRange1d()
ydr = DataRange1d()

plot = Plot(x_range=xdr, y_range=ydr, min_border=80)

circle = Circle(
    x="x", y="y", size="r",
    fill_color="red", line_color="black"
)
plot.add_glyph(source, circle)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

plot.add_tools(PanTool(), WheelZoomTool())

document.add(plot)
session.store_document(document)

link = session.object_link(document.context)
print ("please visit %s to see plots" % link)
Exemplo n.º 8
0
    def __init__(self, **kwargs):
        names = [
            'processes', 'disk-read', 'cores', 'cpu', 'disk-write', 'memory',
            'last-seen', 'memory_percent', 'host'
        ]
        self.source = ColumnDataSource({k: [] for k in names})

        columns = {
            name: TableColumn(field=name, title=name.replace('_percent', ' %'))
            for name in names
        }

        cnames = [
            'host', 'cores', 'processes', 'memory', 'cpu', 'memory_percent'
        ]

        formatters = {
            'cpu': NumberFormatter(format='0.0 %'),
            'memory_percent': NumberFormatter(format='0.0 %'),
            'memory': NumberFormatter(format='0 b'),
            'latency': NumberFormatter(format='0.00000'),
            'last-seen': NumberFormatter(format='0.000'),
            'disk-read': NumberFormatter(format='0 b'),
            'disk-write': NumberFormatter(format='0 b'),
            'net-send': NumberFormatter(format='0 b'),
            'net-recv': NumberFormatter(format='0 b')
        }

        table = DataTable(
            source=self.source,
            columns=[columns[n] for n in cnames],
        )

        for name in cnames:
            if name in formatters:
                table.columns[cnames.index(name)].formatter = formatters[name]

        mem_plot = Plot(title=Title(text="Memory Usage (%)"),
                        toolbar_location=None,
                        x_range=Range1d(start=0, end=1),
                        y_range=Range1d(start=-0.1, end=0.1),
                        **kwargs)

        mem_plot.add_glyph(
            self.source,
            Circle(x='memory_percent', y=0, size=10, fill_alpha=0.5))

        mem_plot.add_layout(LinearAxis(), 'below')

        hover = HoverTool(point_policy="follow_mouse",
                          tooltips="""
                <div>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">@host: </span>
                  <span style="font-size: 10px; font-family: Monaco, monospace;">@memory_percent</span>
                </div>
                """)
        mem_plot.add_tools(hover, BoxSelectTool())

        if 'sizing_mode' in kwargs:
            sizing_mode = {'sizing_mode': kwargs['sizing_mode']}
        else:
            sizing_mode = {}

        self.root = column(mem_plot,
                           table,
                           id='bk-worker-table',
                           **sizing_mode)
Exemplo n.º 9
0
    def make_plot(self):

        self.p = figure(
            x_axis_label="Date",
            x_axis_type="datetime",
            y_axis_label="Total Cases and Deaths",
            width=900,
        )

        self.p.extra_y_ranges = {"ratio_axis": Range1d()}

        axis = LinearAxis(y_range_name="ratio_axis")
        axis.formatter = NumeralTickFormatter(format="0 %")
        self.p.add_layout(axis, "right")

        colors = Category20_3

        self.p.line(
            source=self.src,
            x="date",
            y="cases",
            line_width=2,
            color=colors[0],
            legend_label="Cases",
        )
        self.p.line(
            source=self.src,
            x="date",
            y="deaths",
            line_width=2,
            color=colors[1],
            legend_label="Deaths",
        )
        self.p.line(
            source=self.src,
            x="date",
            y="ratio",
            line_width=2,
            y_range_name="ratio_axis",
            color=colors[2],
            legend_label="Deaths/Cases",
        )

        self.p.legend.location = "top_left"

        self.logp = figure(
            x_axis_label="Date",
            x_axis_type="datetime",
            y_axis_label="Total Cases and Deaths",
            y_axis_type="log",
            width=900,
        )

        self.logp.extra_y_ranges = {"ratio_axis": Range1d()}

        logaxis = LogAxis(y_range_name="ratio_axis")
        logaxis.formatter = NumeralTickFormatter(format="0 %")
        self.logp.add_layout(logaxis, "right")

        self.logp.line(
            source=self.src,
            x="date",
            y="cases",
            line_width=2,
            color=colors[0],
            legend_label="Cases",
        )
        self.logp.line(
            source=self.src,
            x="date",
            y="deaths",
            line_width=2,
            color=colors[1],
            legend_label="Deaths",
        )
        self.logp.line(
            source=self.src,
            x="date",
            y="ratio",
            line_width=2,
            y_range_name="ratio_axis",
            color=colors[2],
            legend_label="Deaths/Cases",
        )

        self.p.legend.location = "top_left"
Exemplo n.º 10
0
    microseconds=['%F %T.%3N'],
    milliseconds=['%F %T.%3N'],
    seconds=['%F %T'],
    minsec=['%F %T'],
    minutes=['%F %T'],
    hourmin=['%F %T'],
    hours=['%F %T'],
    days=['%F %T'],
    months=['%F %T'],
    years=['%F %T'],
)
p.xaxis.major_label_orientation = 0.7  #1.571 #math.pi/2

p.xaxis.axis_label = "T"
p.extra_y_ranges = {'RH': Range1d(bounds=(0, 100), start=0, end=100)}
p.add_layout(LinearAxis(y_range_name='foo', axis_label='RH'), 'right')

p.line(x='time', y='T', alpha=0.5, line_width=1, color='red', source=source)
p.line(x='time',
       y='RH',
       alpha=0.5,
       line_width=1,
       color='blue',
       source=source,
       y_range_name='foo')


def _read_sensor():
    timeval = datetime.datetime.now()  #pd.to_datetime('now')
    #int(time.time()*1000000)
    #T = np.random.normal(0, 1)
Exemplo n.º 11
0
def generate_stack(name,
                   var_label=None,
                   auto_color=True,
                   combine_axes=True,
                   interactive=True):

    doc.curdoc().clear()
    num_plots = len(name)

    # Name for .html file containing plots
    out_name = ""

    if isinstance(var_label, int):
        var_label = list(pytplot.data_quants.keys())[var_label]

    # Vertical Box layout to store plots
    all_plots = []
    axis_types = []
    i = 0

    # Configure plot sizes
    total_psize = 0
    j = 0
    while (j < num_plots):
        total_psize += pytplot.data_quants[name[j]].extras['panel_size']
        j += 1

    p_to_use = pytplot.tplot_opt_glob['window_size'][1] / total_psize

    # Create all plots
    while (i < num_plots):
        last_plot = (i == num_plots - 1)

        p_height = int(pytplot.data_quants[name[i]].extras['panel_size'] *
                       p_to_use)
        p_width = pytplot.tplot_opt_glob['window_size'][0]

        #Check plot type
        new_fig = _get_figure_class(name[i],
                                    auto_color=auto_color,
                                    interactive=interactive,
                                    show_xaxis=last_plot)

        new_fig.setsize(height=p_height, width=p_width)

        if i == 0:
            new_fig.add_title()

        axis_types.append(new_fig.getaxistype())

        new_fig.buildfigure()

        # Add name of variable to output file name
        if last_plot:
            out_name += name[i]
        else:
            out_name += name[i] + '+'

        # Add plot to GridPlot layout
        all_plots.append(new_fig.getfig())
        i = i + 1

    #Add the time stamp to the stack
    total_string = ""
    if 'time_stamp' in pytplot.extra_layouts:
        total_string = pytplot.extra_layouts['time_stamp']

    ts = TimeStamp(text=total_string)
    pytplot.extra_layouts['data_time'] = ts
    all_plots.append([pytplot.extra_layouts['data_time']])

    #Add extra x axes if applicable
    if var_label is not None:
        if not isinstance(var_label, list):
            var_label = [var_label]
        x_axes = []
        x_axes_index = 0
        for new_x_axis in var_label:

            axis_data_quant = pytplot.data_quants[new_x_axis]
            axis_start = min(axis_data_quant.data.min(skipna=True).tolist())
            axis_end = max(axis_data_quant.data.max(skipna=True).tolist())
            x_axes.append(Range1d(start=axis_start, end=axis_end))
            k = 0
            while (k < num_plots):
                all_plots[k][0].extra_x_ranges[
                    'extra_' + str(new_x_axis)] = x_axes[x_axes_index]
                k += 1
            all_plots[k - 1][0].add_layout(
                LinearAxis(x_range_name='extra_' + str(new_x_axis)), 'below')
            all_plots[k - 1][0].plot_height += 22
            x_axes_index += 1

    # Set all plots' x_range and plot_width to that of the bottom plot
    #     so all plots will pan and be resized together.
    first_type = {}
    if combine_axes:
        k = 0
        while (k < len(axis_types)):
            if axis_types[k][0] not in first_type:
                first_type[axis_types[k][0]] = k
            else:
                all_plots[k][0].x_range = all_plots[first_type[axis_types[k]
                                                               [0]]][0].x_range
                if axis_types[k][1]:
                    all_plots[k][0].y_range = all_plots[first_type[
                        axis_types[k][0]]][0].y_range
            k += 1

    return gridplot(all_plots)
Exemplo n.º 12
0
                editor=SelectEditor(options=classes)),
    TableColumn(field="cty", title="City MPG", editor=IntEditor()),
    TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()),
]
data_table = DataTable(source=source,
                       columns=columns,
                       editable=True,
                       width=1000,
                       index_position=-1,
                       index_header="row index",
                       index_width=60)

plot = Plot(title=None, plot_width=1000, plot_height=300)

# Set up x & y axis
plot.add_layout(LinearAxis(), 'below')
yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

# Add Glyphs
cty_glyph = Circle(x="index",
                   y="cty",
                   fill_color="#396285",
                   size=8,
                   fill_alpha=0.5,
                   line_alpha=0.5)
hwy_glyph = Circle(x="index",
                   y="hwy",
                   fill_color="#CE603D",
                   size=8,
Exemplo n.º 13
0
    # column in your data source. Uncomment the following line
    # to see the effect.
    # fill_alpha=0.2,

    # An alternative form that explicitly sets a default value:
    #fill_color={"default": "red", "field": "color"},

    # Note that line_color is set to a fixed value. This can be any of
    # the SVG named 147 colors, or a hex color string starting with "#",
    # or a string "rgb(r,g,b)" or "rgba(r,g,b,a)".
    # Any other string will be interpreted as a field name to look up
    # on the datasource.
    line_color="black")

plot.add_glyph(source, circle)

plot.add_layout(LinearAxis(), 'below')
plot.add_layout(LinearAxis(), 'left')

plot.add_tools(PanTool(), WheelZoomTool())

doc = Document()
doc.add(plot)

if __name__ == "__main__":
    filename = "colorspec.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Demonstration of ColorSpec"))
    print("Wrote %s" % filename)
    view(filename)
Exemplo n.º 14
0
def roi_cost(width, height, title_text, title_align):
    df = pd.read_sql(
        """SELECT YEAR([P].[DATA]) AS [ROK], [P].[SEC_COST] AS [KOSZT], [PREMIUM].[PREMIUM] FROM
                        [PORTFEL_IN_TIME_VW] AS [P],
                        (SELECT YEAR([DATA]) AS [ROK], MAX([DATA]) AS [MAXDATA] FROM [PORTFEL_IN_TIME_VW] GROUP BY YEAR([DATA])) AS [DATES],
                        (SELECT [ROK], SUM([VAL]) AS [PREMIUM] FROM [PREMIUM_VW] GROUP BY [ROK]) AS [PREMIUM]
                        WHERE [P].[NAZWA] = 'Razem'
                        AND [P].[DATA] = [DATES].[MAXDATA]
                        AND YEAR([P].[DATA]) = [PREMIUM].[ROK]
                        OPTION (MAXRECURSION 0)""", conn)
    #wyliczenie ROI
    df['ROI'] = df['PREMIUM'] / df['KOSZT']
    #dane
    source = ColumnDataSource(data=df)
    p = figure(x_range=(min(df['ROK']) - 0.35, max(df['ROK']) + 0.35),
               plot_width=width,
               plot_height=height,
               toolbar_location=None)

    #oś dodatkowa dla ROI
    p.extra_y_ranges = {'roi': Range1d(start=0, end=max(df['ROI']) * 1.5)}
    p.add_layout(LinearAxis(y_range_name='roi'), 'right')

    #budowa słupków
    p.vbar(name='KOSZT',
           x='ROK',
           top='KOSZT',
           width=0.5,
           color=colors[0],
           source=source)
    #linia z ROI
    p.line(name='ROI',
           x='ROK',
           y='ROI',
           line_width=5,
           color=colors[1],
           source=source,
           y_range_name='roi')

    hover = HoverTool(tooltips=[('', '@ROK'), ('Koszt', '@KOSZT{0,0.00}'),
                                ('Przychody', '@PREMIUM{0,0.00}'),
                                ('ROI', '@ROI{0,0.00%}')],
                      mode='mouse',
                      renderers=[p.renderers[0]])
    p.add_tools(hover)
    p.yaxis[0].formatter = NumeralTickFormatter(format="0,00 a")
    p.yaxis[0].axis_label = "Koszt portfela"
    p.yaxis[1].formatter = NumeralTickFormatter(format="0.00 %")
    p.yaxis[1].axis_label = "Stopa zwrotu"
    p.xaxis.ticker.max_interval = 1
    p.xaxis.ticker.min_interval = 1
    p.axis.minor_tick_in = 0
    p.axis.minor_tick_out = 0
    p.ygrid.grid_line_width = 0
    p.xgrid.grid_line_width = 0
    p.outline_line_color = None
    p.border_fill_color = None
    #tytuł
    p.title.text = title_text
    p.title.align = title_align
    return p
    def plot_time_evol(
        self,
        tracts=None,
        figs_output_dir='',
        scripts_output_dir='',
        div_output_dir='',
    ):
        """Plot response time and number of incidents as a function of time.

        If `tracts` is not provided, the method generates plots for each tract
        in the database. The `tracts` parameter is expected to be a list of
        strings (not zero-padded), though the method will attempt to convert
        it to the correct data type otherwise."""

        tracts = self._get_tracts(tracts)

        for tr in tracts:
            # filter dataset by date and tract
            df_tmp = self._get_response_time_and_priority_df(tr)

            median_response_time = self._group_median_response_time(
                df_tmp,
                GROUPING_FREQ,
            )

            total_num_incidents = self._group_num_incidents(
                df_tmp,
                GROUPING_FREQ,
            )

            priority_groups = self._group_priority(
                df_tmp,
                GROUPING_FREQ,
            )

            tract_geometry, cntr_lng, cntr_lat = get_tract_geom(tr)

            output_file(figs_output_dir + f"stats_tract{tr}.html")
            tools = "pan,wheel_zoom,box_zoom,crosshair,reset"

            p1 = figure(
                plot_width=1200,
                plot_height=400,
                x_axis_type='datetime',
                x_axis_label='Date',
                y_axis_label='Median Response Time (minutes)',
                toolbar_location="above",
                tools=tools,
            )

            p1.yaxis.axis_label_text_font_size = '12pt'
            p1.yaxis.major_label_text_font_size = '10pt'
            p1.yaxis.axis_label_text_color = 'steelblue'

            p1.xaxis.axis_label_text_font_size = '12pt'
            p1.xaxis.major_label_text_font_size = '10pt'

            p1.line(
                median_response_time.index,
                median_response_time.values,
                line_width=5,
                color='steelblue',
                alpha=0.75,
                legend_label='Median Response Time',
            )

            p1.y_range = Range1d(
                min(median_response_time) * 0.95,
                max(median_response_time) * 1.05,
            )

            p1.extra_y_ranges = {
                'NumIncidents': Range1d(
                    start=min(total_num_incidents) * 0.95,
                    end=max(total_num_incidents) * 1.05,
                )
            }
            p1.add_layout(
                LinearAxis(
                    y_range_name='NumIncidents',
                    axis_label='Number of Incidents',
                    axis_label_text_font_size='12pt',
                    axis_label_text_color='firebrick',
                    major_label_text_font_size='10pt',
                ),
                'right',
            )

            p1.line(
                total_num_incidents.index,
                total_num_incidents.values,
                line_width=5,
                color='firebrick',
                alpha=0.75,
                y_range_name='NumIncidents',
                legend_label='Number of Incidents',
            )

            p1.legend.location = "top_left"
            p1.legend.click_policy = "hide"

            p2 = figure(
                plot_width=800,
                plot_height=400,
                x_axis_type='datetime',
                x_axis_label='Date',
                y_axis_label='Number of Incidents',
                toolbar_location="above",
                tools=tools,
                x_range=p1.x_range,
            )

            p2.min_border_left = 150

            p2.y_range.start = 0

            p2.yaxis.axis_label_text_font_size = '12pt'
            p2.yaxis.major_label_text_font_size = '10pt'

            p2.xaxis.axis_label_text_font_size = '12pt'
            p2.xaxis.major_label_text_font_size = '10pt'

            stacked_area_source = ColumnDataSource(
                data=dict(
                    x=median_response_time.index
                )
            )
            for pc in PRIORITY_CODES:
                stacked_area_source.add(
                    priority_groups[pc],
                    name=pc,
                )

            p2.varea_stack(
                PRIORITY_CODES,
                x='x',
                source=stacked_area_source,
                color=('#bf9f84', 'darkolivegreen', '#e7cb75'),
                alpha=0.75,
                legend_label=[f"Priority {pc}" for pc in PRIORITY_CODES],
            )

            p2.legend.location = 'top_left'
            p2.legend.orientation = 'horizontal'
            p2.legend.spacing = 20

            tools = "pan,wheel_zoom,reset,save"
            map_options = GMapOptions(
                lat=cntr_lat,
                lng=cntr_lng,
                map_type="roadmap",
                zoom=14
            )

            p3 = gmap(
                GMAP_API_KEY,
                map_options,
                width=420,
                height=400,
                tools=tools,
                toolbar_location='above'
            )

            p3.yaxis.visible=False
            p3.xaxis.visible=False
            p3.min_border_left = 50

            lng_coords, lat_coords = [], []
            for pg in list(tract_geometry.geoms):
                c = pg.exterior.coords.xy
                lng_coords.append(list(c[0]))
                lat_coords.append(list(c[1]))

            source = ColumnDataSource(
                data=dict(
                    x=lng_coords,
                    y=lat_coords,
                )
            )

            p3.patches(
                'x', 'y',
                source=source,
                fill_color='darkslateblue',
                fill_alpha=0.5,
                line_color="black",
                line_width=1,
            )

            p = layout([[p3, p2], [p1]], spacing=50)

            save(p)

            script, div = components(p)

            with open(
                scripts_output_dir + f"stats_script_tract{tr}.js", 'w'
            ) as f:
                f.write(script)

            with open(
                div_output_dir + f"stats_div_tract{tr}.html", 'w'
            ) as f:
                f.write(div)

        return None
Exemplo n.º 16
0
        sepal_length=flowers['sepal_length'],
        sepal_width=flowers['sepal_width'],
        color=flowers['color']
    )
)

plot = Plot(plot_width=800, plot_height=400)
plot.title.text = "Iris Data"

circle = Circle(
    x="petal_length", y="petal_width", size=10,
    fill_color="color", fill_alpha=0.2, line_color="color"
)
plot.add_glyph(source, circle)

xaxis = LinearAxis(axis_label="petal length", major_tick_in=0)
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis(axis_label="petal width", major_tick_in=0)
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

plot.add_tools(PanTool(), WheelZoomTool())

# Add a caption as a title placed in "below" layout panel.
msg = """The Iris flower data set, or Fisher's Iris data set, is a multivariate data set introduced by Ronald Fisher in his 1936 paper."""
caption = Title(text=msg, align='left', text_font_size='10pt')
plot.add_layout(caption, 'below')
Exemplo n.º 17
0
x2 = np.linspace(1.5, 5.5, 5)
z = x2 + 2 * np.cos((x2 - 1) * np.pi)

source1 = ColumnDataSource({
    "x": [1, 2, 3, 4, 5],
    "y": [1, 2, 3, 4, 5],
    "who": ["a", "b", "c", "d", "e"]
})
source2 = ColumnDataSource({"x": x, "y": y})
source3 = ColumnDataSource({"x": x2, "y": z})
source4 = ColumnDataSource({"y": [2.5], "x": [0.5]})

plot = Plot(width=300, height=300)
plot.title = Title(text="Themed glyphs")

xaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter())
yaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter())
plot.add_layout(xaxis, "below")
plot.add_layout(yaxis, "left")

plot.add_glyph(source1, Scatter(x="x", y="y", marker="diamond", size=20))
plot.add_glyph(source1, Text(x=dodge("x", -0.2), y=dodge("y", 0.1),
                             text="who"))
plot.add_glyph(source2, Line(x="x", y="y"))
plot.add_glyph(source3, Ellipse(x="x",
                                y="y",
                                width=0.2,
                                height=0.3,
                                angle=-0.7))
plot.add_glyph(source4, glyph=HBar(y="y", right="x", height=1.5))
Exemplo n.º 18
0
def plot_picture(dates,
                 states,
                 var_values,
                 confidence_values,
                 save_path,
                 name_dict,
                 s_size=0.1):
    ## Fig 생성
    fig = figure(title=name_dict['title'],
                 x_axis_label='Timeline',
                 x_axis_type='datetime',
                 y_axis_label='score',
                 plot_width=2000,
                 plot_height=500)

    fig.y_range = Range1d(start=min(var_values), end=max(var_values))
    fig.line(dates,
             var_values,
             line_width=2,
             color=name_dict['var_color'],
             legend_label=name_dict['var_name'])

    if states is not None and len(dates) > 0:
        temp_start = dates[0]
        temp_state = states[0]

        temp_date = dates[0]
        for xc, value in zip(dates, states):
            if temp_state != value:
                if temp_state == 'prognosis':
                    fig.add_layout(
                        BoxAnnotation(left=temp_start,
                                      right=temp_date,
                                      fill_alpha=0.2,
                                      fill_color='blue'))
                if temp_state == 'abnormal':
                    fig.add_layout(
                        BoxAnnotation(left=temp_start,
                                      right=temp_date,
                                      fill_alpha=0.2,
                                      fill_color='orange'))
                temp_start = xc
                temp_state = value
            temp_date = xc

        if temp_state == 'prognosis':
            fig.add_layout(
                BoxAnnotation(left=temp_start,
                              right=xc,
                              fill_alpha=0.2,
                              fill_color='blue'))
        if temp_state == 'abnormal':
            fig.add_layout(
                BoxAnnotation(left=temp_start,
                              right=xc,
                              fill_alpha=0.2,
                              fill_color='orange'))

    if confidence_values is not None:
        fig.extra_y_ranges = {
            "var": Range1d(start=-1, end=max(confidence_values) + 1)
        }
        fig.add_layout(LinearAxis(y_range_name="var"), 'right')
        fig.line(dates,
                 confidence_values,
                 legend_label=name_dict['confidence_name'],
                 line_width=2,
                 y_range_name='var',
                 color=name_dict['confidence_color'],
                 line_alpha=.3)

    fig.legend.click_policy = 'hide'
    output_file(filename=save_path)
    save(fig)
Exemplo n.º 19
0
def plot_resources(results, palette="Viridis", **kwargs):
    """Plot resource usage in a bokeh plot.

    Parameters
    ----------
    results : sequence
        Output of ResourceProfiler.results
    palette : string, optional
        Name of the bokeh palette to use, must be a member of
        bokeh.palettes.all_palettes.
    **kwargs
        Other keyword arguments, passed to bokeh.figure. These will override
        all defaults set by plot_resources.

    Returns
    -------
    The completed bokeh plot object.
    """
    bp = import_required("bokeh.plotting", _BOKEH_MISSING_MSG)
    import bokeh
    from bokeh import palettes
    from bokeh.models import LinearAxis, Range1d

    defaults = dict(
        title="Profile Results",
        tools="save,reset,xwheel_zoom,xpan",
        toolbar_location="above",
        width=800,
        height=300,
    )
    # Support plot_width and plot_height for backwards compatibility
    if "plot_width" in kwargs:
        kwargs["width"] = kwargs.pop("plot_width")
    if "plot_height" in kwargs:
        kwargs["height"] = kwargs.pop("plot_height")

    # Drop `label_size` to match `plot_cache` and `plot_tasks` kwargs
    if "label_size" in kwargs:
        kwargs.pop("label_size")

    defaults.update(**kwargs)

    if results:
        t, mem, cpu = zip(*results)
        left, right = min(t), max(t)
        t = [i - left for i in t]
        p = bp.figure(y_range=fix_bounds(0, max(cpu), 100),
                      x_range=fix_bounds(0, right - left, 1),
                      **defaults)
    else:
        t = mem = cpu = []
        p = bp.figure(y_range=(0, 100), x_range=(0, 1), **defaults)
    colors = palettes.all_palettes[palette][6]
    p.line(
        t,
        cpu,
        color=colors[0],
        line_width=4,
        **{
            "legend_label" if LooseVersion(bokeh.__version__) >= "1.4" else "legend":
            "% CPU"
        })
    p.yaxis.axis_label = "% CPU"
    p.extra_y_ranges = {
        "memory":
        Range1d(
            *fix_bounds(min(mem) if mem else 0,
                        max(mem) if mem else 100, 100))
    }
    p.line(
        t,
        mem,
        color=colors[2],
        y_range_name="memory",
        line_width=4,
        **{
            "legend_label" if LooseVersion(bokeh.__version__) >= "1.4" else "legend":
            "Memory"
        })
    p.add_layout(LinearAxis(y_range_name="memory", axis_label="Memory (MB)"),
                 "right")
    p.xaxis.axis_label = "Time (s)"
    return p
Exemplo n.º 20
0
def update_scale(attr, old, new):
    ticker = LinearAxis()
    if new == "Log scale":
        ticker = LogAxis()
    pairplots['dimdem'].yaxis[0] = ticker
Exemplo n.º 21
0
              plot_height=600,
              toolbar_location=None,
              outline_line_color=None,
              y_axis_type=None)

plot.title.text = "Usain Bolt vs. 116 years of Olympic sprinters"
plot.title.text_font_size = "14pt"

plot.xaxis.ticker = SingleIntervalTicker(interval=5, num_minor_ticks=0)
plot.xaxis.axis_line_color = None
plot.xaxis.major_tick_line_color = None
plot.xgrid.grid_line_dash = "dashed"

yticker = FixedTicker(
    ticks=[1900, 1912, 1924, 1936, 1952, 1964, 1976, 1988, 2000, 2012])
yaxis = LinearAxis(ticker=yticker, major_tick_in=-5, major_tick_out=10)
plot.add_layout(yaxis, "right")

radius = dict(value=5, units="screen")
medal = plot.circle(x="MetersBack",
                    y="Year",
                    radius=radius,
                    fill_color="MedalFill",
                    line_color="MedalLine",
                    fill_alpha=0.5,
                    source=source,
                    level="overlay")
#medal_glyph = Circle(x="MetersBack", y="Year", radius=radius, fill_color="MedalFill", line_color="MedalLine", fill_alpha=0.5)
#medal = plot.add_glyph(source, medal_glyph)

athlete_glyph = Text(x="MetersBack",
Exemplo n.º 22
0
p.circle(x='Date', y='dowjclose', name='dowj', alpha=0, source=source2, size=3)

p.circle(x='Date',
         y='XOMclose',
         name='xom',
         alpha=0,
         source=source2,
         size=3,
         y_range_name='foo')

# Setting the second y axis range name and range
p.extra_y_ranges = {"foo": Range1d(start=50, end=150)}

# Adding the second axis to the plot.
p.add_layout(LinearAxis(y_range_name="foo"), 'right')

p.multi_line(name='bill',
             xs=xom[0],
             ys=xom[1],
             color=xom[2],
             line_width=3,
             y_range_name='foo')

p.multi_line(name='steve', xs=dowj[0], ys=dowj[1], color=dowj[2], line_width=3)

p.add_tools(
    HoverTool(names=['dowj'],
              mode="vline",
              line_policy='nearest',
              point_policy='snap_to_data',
Exemplo n.º 23
0
    start=sprint.MetersBack.max() + 2,
    end=0)  # XXX: +2 is poor-man's padding (otherwise misses last tick)
ydr = DataRange1d(range_padding=0.05)  # XXX: should be 2 years (both sides)

plot = Plot(x_range=xdr,
            y_range=ydr,
            plot_width=1000,
            plot_height=600,
            toolbar_location=None,
            outline_line_color=None)
plot.title.text = "Usain Bolt vs. 116 years of Olympic sprinters"

xticker = SingleIntervalTicker(interval=5, num_minor_ticks=0)
xaxis = LinearAxis(ticker=xticker,
                   axis_line_color=None,
                   major_tick_line_color=None,
                   axis_label="Meters behind 2012 Bolt",
                   axis_label_text_font_size="10pt",
                   axis_label_text_font_style="bold")
plot.add_layout(xaxis, "below")
xgrid = Grid(dimension=0, ticker=xaxis.ticker, grid_line_dash="dashed")
plot.add_layout(xgrid)
yticker = SingleIntervalTicker(interval=12, num_minor_ticks=0)
yaxis = LinearAxis(ticker=yticker, major_tick_in=-5, major_tick_out=10)
plot.add_layout(yaxis, "right")

radius = dict(value=5, units="screen")
medal_glyph = Circle(x="MetersBack",
                     y="Year",
                     radius=radius,
                     fill_color="MedalFill",
                     line_color="MedalLine",
Exemplo n.º 24
0
def timeLineChartWind(data, details='', width=set_w, height=set_h):
    x_name = 'Time'

    if len(details['icao']) > 0:
        location = ' at ' + details['icao'].upper()
    else:
        location = ''

    xdr = DataRange1d(start=data[x_name][0], end=data[x_name][-1])
    maxspd, minspd = max(np.nanmax(data['Wind Speed']),
                         np.nanmax(data['Wind Gust'])) + 1, np.nanmax(
                             min(data['Wind Speed']) - 1, 0)
    ydr = DataRange1d(start=minspd, end=maxspd)

    sv_plotcolour_spd = '#53f3ae'
    sv_plotcolour_dir = '#9f54bb'

    plot = figure(title='Wind' + location +
                  ' (Gusts shown only if reportable)',
                  plot_width=width,
                  plot_height=height,
                  x_axis_type='datetime',
                  x_range=xdr,
                  y_range=ydr,
                  toolbar_location=None,
                  sizing_mode='stretch_both')
    makeCirclePlot(plot, data, 'Wind Speed', sv_plotcolour_spd)
    speed_plot = makeLinePlot(plot, data, 'Wind Speed', sv_plotcolour_spd)
    plot.add_tools(
        HoverTool(
            renderers=[speed_plot],
            tooltips='@{Wind Direction} @{Wind Speed}KT at @Time{%H%MZ}',
            mode='vline',  # use 'mouse' for only over points
            formatters={'@Time': 'datetime'},
            show_arrow=False,
        ))
    gust_plot_hidden = makeLinePlot(plot,
                                    data,
                                    'Wind Gust',
                                    'red',
                                    line_alpha=0)
    gust_plot = makeCirclePlot(plot,
                               data,
                               'Wind Gust',
                               sv_plotcolour_spd,
                               size=12)
    plot.add_tools(
        HoverTool(
            renderers=[gust_plot_hidden],
            tooltips='Reported gust of @{Wind Gust}KT at @Time{%H%MZ}',
            mode='vline',  # use 'mouse' for only over points
            formatters={'@Time': 'datetime'},
            show_arrow=False,
        ))
    plot.yaxis.axis_label = 'Wind speed/gust (KT)'

    setLook(plot)
    #plot.yaxis.axis_line_color = sv_plotcolour_spd
    #plot.yaxis.axis_label_text_color = sv_plotcolour_spd
    #plot.yaxis.major_label_text_color = sv_plotcolour_spd
    #plot.yaxis.major_tick_line_color = sv_plotcolour_spd

    plot.extra_y_ranges['dir'] = DataRange1d(start=0, end=360)
    plot.add_layout(
        LinearAxis(y_range_name='dir',
                   axis_label='Wind direction (degrees)',
                   axis_line_color=sv_plotcolour_dir,
                   axis_label_text_color=sv_plotcolour_dir,
                   major_label_text_color=sv_plotcolour_dir,
                   major_tick_line_color=sv_plotcolour_dir,
                   minor_tick_line_color=sv_plotcolour_dir), 'right')
    dir_plot = makeLinePlot(plot,
                            data,
                            'Wind Direction',
                            sv_plotcolour_dir,
                            line_alpha=0.5)
    dir_plot.y_range_name = 'dir'

    return components(plot)
Exemplo n.º 25
0
def hist(df, feature, bins=50):
    '''Plots bokeh histogram, PDF & CDF of a DF feature.
    
    Parameters
    ----------
    df : DataFrame
        DF of the data.
    feature :  str
        Column name of the df.
    bins : int
        Number of bins to plot.
        
    Returns
    -------
    None
    '''

    #not nan feature values
    x = df[feature][df[feature].notna()].values

    #Get the values for the histogram and bin edges (length(hist)+1)/
    #Use density to plot pdf and cdf on the same plot.
    hist, edges = np.histogram(x, bins=bins, density=True)

    ### PDF & CDF ##

    #find normal distribution parameters
    mu, sigma = norm.fit(x)
    xs = np.linspace(min(x), max(x) + 1, len(x))  #x values to plot the line(s)

    pdf = norm.pdf(xs, loc=mu, scale=sigma)  #probability distribution function
    cdf = norm.cdf(xs, loc=mu, scale=sigma)  #cumulative distribution function

    #data sources for cdf
    source_cdf = ColumnDataSource({'cdf': cdf, 'xs': xs})

    #create the canvas
    p1 = figure(title='Histogram, PDF & CDF',
                plot_height=400,
                x_axis_label=feature,
                y_axis_label='Density')

    #add histogram
    p1.quad(bottom=0,
            top=hist,
            left=edges[:-1],
            right=edges[1:],
            fill_color='royalblue',
            line_color='black',
            alpha=0.7)

    #add pdf
    p1.line(xs,
            pdf,
            line_color='red',
            line_width=5,
            alpha=0.5,
            legend_label='PDF')

    #set left-hand y-axis range
    p1.y_range = Range1d(0, max(hist) + 0.05 * max(hist))

    #setting the second y axis range name and range
    p1.extra_y_ranges = {"cdf": Range1d(start=0, end=1.05)}

    #adding the second y axis to the plot and to the right.
    p1.add_layout(LinearAxis(y_range_name="cdf", axis_label='CDF'), 'right')

    #add cdf with y range on the right
    cdf_plot = p1.line('xs',
                       'cdf',
                       source=source_cdf,
                       alpha=0.8,
                       line_color='darkgoldenrod',
                       line_width=5,
                       legend_label='CDF',
                       y_range_name='cdf',
                       name='cdf',
                       hover_line_color='green')

    #hover tool
    p1.add_tools(
        HoverTool(renderers=[cdf_plot],
                  tooltips=[('Prob', '@cdf{0.00}')],
                  mode='hline'))

    #figure properties
    p1.xgrid.visible = False

    #hide entries when clocking on a legend
    p1.legend.click_policy = "hide"

    show(p1)
Exemplo n.º 26
0
def timeChartCloud(data, details='', width=set_w, height=set_h * 2):
    x_name = 'Time'
    icao = details['icao']

    if len(icao) > 0:
        location = ' at ' + icao.upper()
    else:
        location = ''

    xdr = DataRange1d(start=data[x_name][0], end=data[x_name][-1])
    #ydr = DataRange1d(start=0,end=15000)
    tick_vals, tick_label_overrides = getHeightmapTicks(icao)
    ydr = DataRange1d(start=mapHeight(0, icao),
                      end=mapHeight(int(tick_label_overrides[max(tick_vals)]),
                                    icao))

    sv_plotcolour_vis = 'white'

    plot = figure(title='Cloud base' + location,
                  plot_width=width,
                  plot_height=height,
                  x_axis_type='datetime',
                  x_range=xdr,
                  y_range=ydr,
                  toolbar_location=None,
                  sizing_mode='stretch_both')
    colourstates, alphas = [], []
    for b in data['Cloud Base']:
        colourstates.append(applyCloudColourState(b))
    data['colourstates'] = colourstates
    for a in data['Cloud Amount']:
        if a in ['SCT', 'BKN', 'OVC']:
            alphas.append(0.6)
        else:
            alphas.append(0.2)
    data['alphas'] = alphas
    cloud_plot = makeCirclePlot(plot,
                                data,
                                'Cloud Base Adjusted',
                                'colourstates',
                                size=15,
                                alpha='alphas')

    plot.add_tools(
        HoverTool(
            renderers=[cloud_plot],
            tooltips='@{Cloud Amount} at @{Cloud Base}FT at @Time{%H%MZ}',
            mode='mouse',  # use 'mouse' for only over points
            formatters={'@Time': 'datetime'},
            show_arrow=False,
        ))

    plot.yaxis.axis_label = 'Height (FT)'
    plot.add_layout(LinearAxis(axis_label='Height (FT)'), 'right')

    plot.yaxis.ticker = tick_vals
    plot.yaxis.major_label_overrides = tick_label_overrides

    setLook(plot)

    return components(plot)
Exemplo n.º 27
0
    def __init__(self, **kwargs):
        self.source = ColumnDataSource(
            data={
                'time': [],
                'cpu': [],
                'memory_percent': [],
                'network-send': [],
                'network-recv': []
            })

        x_range = DataRange1d(follow='end',
                              follow_interval=30000,
                              range_padding=0)

        resource_plot = Plot(x_range=x_range,
                             y_range=Range1d(start=0, end=1),
                             toolbar_location=None,
                             min_border_bottom=10,
                             **kwargs)

        line_opts = dict(line_width=2, line_alpha=0.8)
        g1 = resource_plot.add_glyph(
            self.source,
            Line(x='time',
                 y='memory_percent',
                 line_color="#33a02c",
                 **line_opts))
        g2 = resource_plot.add_glyph(
            self.source,
            Line(x='time', y='cpu', line_color="#1f78b4", **line_opts))

        resource_plot.add_layout(
            LinearAxis(formatter=NumeralTickFormatter(format="0 %")), 'left')

        legend_opts = dict(location='top_left',
                           orientation='horizontal',
                           padding=5,
                           margin=5,
                           label_height=5)

        resource_plot.add_layout(
            Legend(items=[('Memory', [g1]), ('CPU', [g2])], **legend_opts))

        network_plot = Plot(x_range=x_range,
                            y_range=DataRange1d(start=0),
                            toolbar_location=None,
                            **kwargs)
        g1 = network_plot.add_glyph(
            self.source,
            Line(x='time', y='network-send', line_color="#a6cee3",
                 **line_opts))
        g2 = network_plot.add_glyph(
            self.source,
            Line(x='time', y='network-recv', line_color="#b2df8a",
                 **line_opts))

        network_plot.add_layout(DatetimeAxis(axis_label="Time"), "below")
        network_plot.add_layout(LinearAxis(axis_label="MB/s"), 'left')
        network_plot.add_layout(
            Legend(items=[('Network Send', [g1]), ('Network Recv', [g2])],
                   **legend_opts))

        tools = [
            PanTool(dimensions='width'),
            WheelZoomTool(dimensions='width'),
            BoxZoomTool(),
            ResetTool()
        ]

        if 'sizing_mode' in kwargs:
            sizing_mode = {'sizing_mode': kwargs['sizing_mode']}
        else:
            sizing_mode = {}

        combo_toolbar = ToolbarBox(tools=tools,
                                   logo=None,
                                   toolbar_location='right',
                                   **sizing_mode)

        self.root = row(column(resource_plot, network_plot, **sizing_mode),
                        column(combo_toolbar, **sizing_mode),
                        id='bk-resource-profiles-plot',
                        **sizing_mode)

        # Required for update callback
        self.resource_index = [0]
Exemplo n.º 28
0
        sys.exit()

    pncIntf = pncCommListener(pncSocket)
    pncIntf.start()


#update_lock = threading.Lock()
queueLength = figure(title="Buffer Fill Level",
                     plot_width=800,
                     plot_height=400)
r1 = queueLength.line([], [], color="firebrick", line_width=2)

threadTime = figure(title="Z-Axis Encoder", plot_width=800, plot_height=400)
r2 = threadTime.line([], [], color="firebrick", line_width=2)
ticker = SingleIntervalTicker(interval=5, num_minor_ticks=10)
xaxis = LinearAxis(ticker=ticker)
yaxis = LinearAxis(ticker=ticker)

ds1 = r1.data_source
ds2 = r2.data_source


@linear()
def update(step):
    #print(step)
    if pncIntf.needUpdate:
        #print('need to update plots')
        queue_data = pncIntf.data['TCQ']
        encoder_data = pncIntf.data['Encoder']
        #encoder_len = len(encoder_data)
Exemplo n.º 29
0
    def __init__(self, n_rectangles=1000, clear_interval=20000, **kwargs):
        """
        kwargs are applied to the bokeh.models.plots.Plot constructor
        """
        self.n_rectangles = n_rectangles
        self.clear_interval = clear_interval
        self.last = 0

        self.source = ColumnDataSource(
            data=dict(start=[time() - clear_interval],
                      duration=[0.1],
                      key=['start'],
                      name=['start'],
                      color=['white'],
                      worker=['foo'],
                      y=[0],
                      worker_thread=[1],
                      alpha=[0.0]))

        x_range = DataRange1d(range_padding=0)
        y_range = DataRange1d(range_padding=0)

        self.root = Plot(title=Title(text="Task Stream"),
                         id='bk-task-stream-plot',
                         x_range=x_range,
                         y_range=y_range,
                         toolbar_location="above",
                         min_border_right=35,
                         **kwargs)

        self.root.add_glyph(
            self.source,
            Rect(x="start",
                 y="y",
                 width="duration",
                 height=0.4,
                 fill_color="color",
                 line_color="color",
                 line_alpha=0.6,
                 fill_alpha="alpha",
                 line_width=3))

        self.root.add_layout(DatetimeAxis(axis_label="Time"), "below")

        ticker = BasicTicker(num_minor_ticks=0)
        self.root.add_layout(
            LinearAxis(axis_label="Worker Core", ticker=ticker), "left")
        self.root.add_layout(
            Grid(dimension=1, grid_line_alpha=0.4, ticker=ticker))

        self.root.yaxis.major_label_text_alpha = 0

        hover = HoverTool(point_policy="follow_mouse",
                          tooltips="""
                <div>
                    <span style="font-size: 12px; font-weight: bold;">@name:</span>&nbsp;
                    <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
                    <span style="font-size: 10px;">ms</span>&nbsp;
                </div>
                """)

        self.root.add_tools(hover, BoxZoomTool(), ResetTool(reset_size=False),
                            PanTool(dimensions="width"),
                            WheelZoomTool(dimensions="width"))
        if ExportTool:
            export = ExportTool()
            export.register_plot(self.root)
            self.root.add_tools(export)

        # Required for update callback
        self.task_stream_index = [0]
Exemplo n.º 30
0
    def create(self):
        manufacturers = sorted(mpg["manufacturer"].unique())
        models = sorted(mpg["model"].unique())
        transmissions = sorted(mpg["trans"].unique())
        drives = sorted(mpg["drv"].unique())
        classes = sorted(mpg["class"].unique())

        manufacturer_select = Select(title="Manufacturer:",
                                     value="All",
                                     options=["All"] + manufacturers)
        manufacturer_select.on_change('value', self.on_manufacturer_change)
        model_select = Select(title="Model:",
                              value="All",
                              options=["All"] + models)
        model_select.on_change('value', self.on_model_change)
        transmission_select = Select(title="Transmission:",
                                     value="All",
                                     options=["All"] + transmissions)
        transmission_select.on_change('value', self.on_transmission_change)
        drive_select = Select(title="Drive:",
                              value="All",
                              options=["All"] + drives)
        drive_select.on_change('value', self.on_drive_change)
        class_select = Select(title="Class:",
                              value="All",
                              options=["All"] + classes)
        class_select.on_change('value', self.on_class_change)

        columns = [
            TableColumn(field="manufacturer",
                        title="Manufacturer",
                        editor=SelectEditor(options=manufacturers),
                        formatter=StringFormatter(font_style="bold")),
            TableColumn(field="model",
                        title="Model",
                        editor=StringEditor(completions=models)),
            TableColumn(field="displ",
                        title="Displacement",
                        editor=NumberEditor(step=0.1),
                        formatter=NumberFormatter(format="0.0")),
            TableColumn(field="year", title="Year", editor=IntEditor()),
            TableColumn(field="cyl", title="Cylinders", editor=IntEditor()),
            TableColumn(field="trans",
                        title="Transmission",
                        editor=SelectEditor(options=transmissions)),
            TableColumn(field="drv",
                        title="Drive",
                        editor=SelectEditor(options=drives)),
            TableColumn(field="class",
                        title="Class",
                        editor=SelectEditor(options=classes)),
            TableColumn(field="cty", title="City MPG", editor=IntEditor()),
            TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()),
        ]
        data_table = DataTable(source=self.source,
                               columns=columns,
                               editable=True)

        plot = Plot(title=None,
                    x_range=DataRange1d(),
                    y_range=DataRange1d(),
                    plot_width=1000,
                    plot_height=300)

        # Set up x & y axis
        plot.add_layout(LinearAxis(), 'below')
        yaxis = LinearAxis()
        plot.add_layout(yaxis, 'left')
        plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

        # Add Glyphs
        cty_glyph = Circle(x="index",
                           y="cty",
                           fill_color="#396285",
                           size=8,
                           fill_alpha=0.5,
                           line_alpha=0.5)
        hwy_glyph = Circle(x="index",
                           y="hwy",
                           fill_color="#CE603D",
                           size=8,
                           fill_alpha=0.5,
                           line_alpha=0.5)
        cty = plot.add_glyph(self.source, cty_glyph)
        hwy = plot.add_glyph(self.source, hwy_glyph)

        # Add the tools
        tooltips = [
            ("Manufacturer", "@manufacturer"),
            ("Model", "@model"),
            ("Displacement", "@displ"),
            ("Year", "@year"),
            ("Cylinders", "@cyl"),
            ("Transmission", "@trans"),
            ("Drive", "@drv"),
            ("Class", "@class"),
        ]
        cty_hover_tool = HoverTool(renderers=[cty],
                                   tooltips=tooltips + [("City MPG", "@cty")])
        hwy_hover_tool = HoverTool(renderers=[hwy],
                                   tooltips=tooltips +
                                   [("Highway MPG", "@hwy")])
        select_tool = BoxSelectTool(renderers=[cty, hwy], dimensions=['width'])
        plot.add_tools(cty_hover_tool, hwy_hover_tool, select_tool)

        controls = VBox(children=[
            manufacturer_select, model_select, transmission_select,
            drive_select, class_select
        ])
        top_panel = HBox(children=[controls, plot])
        layout = VBox(children=[top_panel, data_table])

        return layout
Exemplo n.º 31
0
def scan_pix_hist(h5_file_name, scurve_sel_pix = 200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]

        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        repeat_command = scan_args['repeat_command']

        np.set_printoptions(threshold=np.nan)
        k = 5
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i) #this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64*64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value

        s_hist = np.swapaxes(ret,0,1)
        indices = np.indices(s_hist.shape)

        param_inx = np.ravel(indices[1].astype(np.float64))#*0.05 - 0.6)
        param_inx_string = param_inx.astype('|S5')

        pix_scan_hist = np.empty((s_hist.shape[1],repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:,param])
            h_count = h_count[:repeat_command+10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='s-scans', palette=Spectral11[::-1], stat=None, plot_width=1000) #, height=4100)

        mean = np.empty(64*64)
        noise = np.empty(64*64)
        x = scan_range_inx
        for pix in range (64*64):
            mu, sigma = analysis.fit_scurve(s_hist[pix], x) #this can multi threaded
            mean[pix] = mu
            noise[pix] = sigma

        px = scurve_sel_pix #1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px) )
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, mean[px], noise[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        mean[mean > scan_range_inx[-1]] = 0
        hist, edges = np.histogram(mean, density=True, bins=50)
	#print "sigma:",noise

        hm_th = figure(title="Threshold", x_axis_label = "pixel #", y_axis_label = "threshold [V]", y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=mean, x=range(64*64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0]*1000*7.6, end=scan_range_inx[-1]*1000*7.6)}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        barray = fit_gauss(edges[2:], hist[1:])
        plt_th_dist = figure(title= 'Threshold Distribution ' + '\sigma = ' + str(round(barray[2],4)) + ' \mu =' + str(round(barray[1],4)), x_axis_label = "threshold [V]", y_range=(0, 1.1*np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649",)
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0]*1000*7.6, end=edges[-1]*1000*7.6)}
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[50], 0.0001),
              gauss(np.arange(edges[1], edges[50], 0.0001), barray[0], barray[1], barray[2]), line_color="#D95B43",
              line_width=8, alpha=0.7)

        noise[noise > 0.02] = 0.02  #this should be done based on 6sigma?
        hist, edges = np.histogram(noise, density=True, bins=50)

        hm_noise = figure(title="Noise", x_axis_label = "pixel #", y_axis_label = "noise [V]", y_range=(0, edges[-1]), plot_width=1000)
        hm_noise.diamond(y=noise, x=range(64*64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1]*1000*7.6)}
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        gauss_params_noise = fit_gauss(edges[5:], hist[4:])
        plt_noise_dist = figure(title='Noise Distribution ' + '\sigma = ' + str(round(gauss_params_noise[2],4)) + ' \mu = ' + str(round(gauss_params_noise[1],4)) , x_axis_label = "noise [V]", y_range=(0, 1.1*np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649",)
        plt_noise_dist.extra_x_ranges = {"e": Range1d(start=edges[0]*1000*7.6, end=edges[-1]*1000*7.6)}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[1],edges[50],0.0001),gauss(np.arange(edges[1],edges[50],0.0001),gauss_params_noise[0],gauss_params_noise[1],gauss_params_noise[2]),line_color="#D95B43", line_width=8, alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise,plt_noise_dist), hplot(hm1, single_scan) ), s_hist
Exemplo n.º 32
0
                else:
                    p.y_range = Range1d(
                        0, np.float(Exp_Des[axis_scale][Test_Name]))
                    p.yaxis.axis_label = y_label

# Set axis options, legend, tickmarks, etc.

            # Secondary y-axis parameters
            if secondary_axis_label:
                if axis_scale == 'Y Scale BDP':
                    p.extra_y_ranges = {
                        secondary_axis_label:
                        Range1d(-secondary_axis_scale, secondary_axis_scale)
                    }
                    p.add_layout(
                        LinearAxis(y_range_name=secondary_axis_label,
                                   axis_label=secondary_axis_label), 'right')
                elif axis_scale == 'Y Scale Temperature':
                    p.extra_y_ranges = {
                        secondary_axis_label: Range1d(-17.78,
                                                      secondary_axis_scale)
                    }
                    p.add_layout(
                        LinearAxis(y_range_name=secondary_axis_label,
                                   axis_label=secondary_axis_label), 'right')
                else:
                    p.extra_y_ranges = {
                        secondary_axis_label: Range1d(0, secondary_axis_scale)
                    }
                    p.add_layout(
                        LinearAxis(y_range_name=secondary_axis_label,
                                   axis_label=secondary_axis_label), 'right')
Exemplo n.º 33
0
    def make(
            self, comp_category='deaths_new_dma_per_1M', regions=None,
            comp_type='vbar', overlay=None, title='', legend_title='Region: Start Date',
            palette_base=Viridis256, palette_flip=False, palette_shift=0, 
            multiline_labels=True, label_offsets={}, fs_labels=8, 
            legend=False, legend_location='top_right',
            x_fontsize=10, y_fontsize=10,
            fs_xticks=16, fs_yticks=16, fs_overlay=10,
            fs_legend=8, h_legend=20, w_legend=20,
            width=750, height=500, base_inc=.25,
            save_file=False, filename=None, annotations=[],
            bg_color='white', bg_alpha=1, border_color='white', border_alpha=1,
        ):
        self.df_comp = self.df[self.df[comp_category].notna()].copy(deep=True)
        
        # If regions are passed, filter the dataframe and reset attributes
        # via `_chart_setup`
        if regions:
            regions = [regions] if isinstance(regions, str) else regions
            self.df_comp = self.df_comp[self.df_comp['region_name'].isin(regions)]
        else:
            regions = list(self.regions)
        
        # Setup additional class attributes
        self.comp_category = comp_category
        self.comp_type = comp_type
        self.palette_base = palette_base
        self.base_inc = base_inc
        self.max_length = self.df.groupby('region_id')['days'].max().max().days + 1
        self.days = [i for i in range(self.max_length)]

        # Set chart attributes
        fs_labels = str(fs_labels) + 'pt'
        min_y = self.df_comp[comp_category].min()
        min_y += min_y * .01
        max_y = self.df_comp[comp_category].max()
        if max_y < 0:
            max_y -= max_y * .1
        else:
            max_y += max_y * .1

        p = figure(
            y_range=Range1d(start=min_y, end=max_y),
            plot_height=height, plot_width=width,
            min_border=0,
            toolbar_location=None,
            title=title,
        )

        # Create the Color Palette
        # An extra color is added and changes in the coloridx are limited
        # to all but the last item, to allow for shifting of palette
        # via palette_shift
        palette_base = np.array(palette_base)
        coloridx = np.round(np.linspace(0, len(palette_base) - 1, len(regions) + 1)).astype(int)
        if palette_flip:
            coloridx[:-1] = coloridx[:-1][::-1]
        if palette_shift:
            coloridx[:-1] += palette_shift
        palette = palette_base[coloridx]
        
        if comp_type == 'multiline':
            ml_data = self._multiline_source()
            ml_data['color'] = palette[:-1]
            source_ml = ColumnDataSource(ml_data)
            p.multi_line(xs='x', ys='y', line_color='color', legend_group='regions', line_width=5, source=source_ml)

            # Setup labels for each line
            if multiline_labels:
                for i in range(len(ml_data['x'])):
                    x_label = int(ml_data['x'][i][-1])
                    y_label = ml_data['y'][i][-1]
                    x_offset = -20
                    y_offset = 5
                    label_region = ml_data['regions'][i]

                    if label_region in label_offsets.keys():
                        x_offset += label_offsets[label_region]['x_offset']
                        y_offset += label_offsets[label_region]['y_offset']
    
                    label = Label(
                        x=x_label, y=y_label, 
                        x_offset=x_offset, y_offset=y_offset,
                        text_font_size=fs_labels, text_color=palette[i], text_alpha=.8,
                        text=label_region, text_font_style='bold',
                        render_mode='canvas'
                    )
                    p.add_layout(label)

        if comp_type == 'vbar':
            vbar_data = self._vbar_source()
            vbar_source = ColumnDataSource(vbar_data)
            increments = self._bar_incrementer(regions)
            
            legend_items = []
            for i, region in enumerate(regions):
                region_start = vbar_data['{}_date'.format(region)][0]
                legend_label = region + ': {}'.format(region_start)

                v = p.vbar(
                    x=dodge('x', increments[i], range=p.x_range), top=region, width=.3, 
                   source=vbar_source, color=palette[i], legend_label=legend_label,
                )
        
        p.legend.visible = legend

        if legend_title:
            p.legend.title = 'Region: Start Date'

        p.legend.location = legend_location
        p.legend.border_line_color = 'black'
        p.legend.glyph_height = h_legend
        p.legend.glyph_width = w_legend
        p.legend.label_height = h_legend
        p.legend.label_width = h_legend

        p.legend.label_text_font_size = str(fs_legend) + 'pt'
        p.legend.background_fill_alpha = 0.0
        p.legend.border_line_alpha = 0.0

        p.xaxis.axis_label = self.labels['days_' + self.start_factor]
        p.xaxis.axis_label_text_font_size = str(x_fontsize) + 'pt'
        p.xaxis.major_label_text_font_size = str(fs_xticks) + 'pt'

        p.yaxis.axis_label = self.labels[comp_category]
        p.yaxis.axis_label_text_font_size = str(y_fontsize) + 'pt'
        p.yaxis.major_label_text_font_size = str(fs_yticks) + 'pt'

        p.xaxis.major_tick_line_color = None
        p.xgrid.grid_line_color = None

        p.min_border = 20

        if overlay:
            overlay_days = []
            overlay_by_region = []
            for region_id, df_group in self.df_comp.groupby('region_id'):
                overlays = list(df_group[overlay].dropna().values)
                overlay_days.append([i for i in range(len(overlays))])
                overlay_by_region.append(overlays)
                
            data2 = {'x': overlay_days, 'y': overlay_by_region, 'color': palette[:-1]}
            source2 = ColumnDataSource(data=data2)
            start = min(olay for region in overlay_by_region for olay in region) * 0.8
            end = max(olay for region in overlay_by_region for olay in region) * 1.1
            p.extra_y_ranges = {overlay: Range1d(start=start, end=end)}
            p.multi_line(xs='x', ys='y', line_color='color', line_width=4, source=source2,
                      y_range_name=overlay, alpha=.3,
            )

            right_axis_label = self.labels[overlay]
            p.add_layout(LinearAxis(y_range_name='{}'.format(overlay), axis_label=right_axis_label, axis_label_text_font_size=str(fs_overlay) + 'pt'), 'right')

        p.xgrid.grid_line_color = None
        p.ygrid.grid_line_color = None
        p.outline_line_color = border_color

        p.background_fill_color = bg_color
        p.background_fill_alpha = bg_alpha
        p.border_fill_color = border_color
        p.border_fill_alpha = border_alpha

        for annot in annotations:
            p.add_layout(Label(**annot))

        if save_file:
            export_png(p, filename=filename)

        return p
Exemplo n.º 34
0
def members_per_month(request: HttpRequest):
    members_per_month = FeeEntry.objects.values('month').order_by('month')\
        .annotate(count=Count('month'))
    df_members = pandas.DataFrame.from_dict(members_per_month)
    df_members['month'] = df_members['month'].map(
        lambda m: m.strftime('%Y-%m'))
    df_members['count_text'] = df_members['count'].map(
        lambda p: '{:.0f}'.format(p))

    df_members = df_members.iloc[1:-1]

    member_fees = FeeEntry.objects.values('month').order_by('month') \
        .annotate(fee=Avg('fee'))
    df_fees = pandas.DataFrame.from_dict(member_fees)
    df_fees['month'] = df_fees['month'].map(lambda m: m.strftime('%Y-%m'))
    df_fees['fee_text'] = df_fees['fee'].map(lambda p: '{:.0f}'.format(p))

    p1: Figure = figure(title="Member pro Monat",
                        x_range=df_members['month'],
                        tooltips=[("Monat", "@month"), ("Anzahl", "@count")],
                        plot_height=300)
    p1.sizing_mode = 'scale_width'

    p1.step(x='month',
            color='navy',
            line_width=3,
            source=df_members,
            y='count',
            legend="Count of Members (paid fees)")

    p1.extra_y_ranges = {
        "fee_range": Range1d(start=0,
                             end=df_fees['fee'].astype(float).max() + 5)
    }
    p1.add_layout(LinearAxis(y_range_name="fee_range"), 'right')
    p1.step(x='month',
            y='fee',
            color='firebrick',
            source=df_fees,
            line_width=2,
            y_range_name="fee_range",
            legend="Average Fee per member")

    labels = LabelSet(x='month',
                      y='fee',
                      text='fee_text',
                      level='glyph',
                      x_offset=-10,
                      y_offset=10,
                      source=ColumnDataSource(df_fees),
                      text_font_size="9pt",
                      y_range_name="fee_range")
    p1.add_layout(labels)

    labels = LabelSet(x='month',
                      y='count',
                      text='count_text',
                      level='glyph',
                      x_offset=-15,
                      y_offset=10,
                      source=ColumnDataSource(df_members),
                      text_font_size="9pt")
    p1.add_layout(labels)

    p1.y_range.start = 0
    p1.y_range.end = df_members['count'].max() + 4
    p1.x_range.range_padding = 0.1
    p1.xaxis.axis_label = "Monat"
    p1.xaxis.major_label_orientation = 1.2
    #p1.outline_line_color = None
    p1.legend.location = 'bottom_right'

    html = embed.file_html(p1, resources.CDN, "Member pro Monat")

    return render(request, 'graph.html', {'html': mark_safe(html)})
Exemplo n.º 35
0
plot2 = figure(y_range=(-3, 3),
               x_range=(0, 3),
               plot_width=400,
               plot_height=400,
               x_axis_type=None,
               y_axis_label='y_i value')
plot2.line(x='xs', y='ys', source=source4)
plot2.scatter('xs',
              'ys',
              color='colors',
              source=source4,
              line_width=3,
              line_alpha=0.6)
ticker = SingleIntervalTicker(interval=1, num_minor_ticks=0)
xaxis = LinearAxis(ticker=ticker, axis_label='y index')
plot2.add_layout(xaxis, 'below')

resample_Button = Button(label="Resample")
covariance_slider = Slider(start=0.0,
                           end=.99,
                           value=0,
                           step=.01,
                           title="Covariance")
x1_slider = Slider(start=-2.5, end=2.5, value=0, step=.1, title="y1")

resample_Button.on_click(lambda: resample_wrapper())
covariance_slider.on_change('value', lambda attr, old, new: update_all())
x1_slider.on_change('value', lambda attr, old, new: update_xs())

controls = [covariance_slider, x1_slider, resample_Button]
def generate_sentiment_ts_plot(sentiment_ts_data, sentiment_ts_sample_count):
    tooltips = [
        ("Date", "@date{%F}"),
        ("Mentions", "@Count"),
        ("Nett Sentiment (7 day mean)", "@NettSentiment{0.0%}"),
    ]

    line_plot = figure(title=None,
                       width=None,
                       height=None,
                       sizing_mode="scale_both",
                       x_range=(sentiment_ts_data["date"].min(),
                                sentiment_ts_data["date"].max()),
                       x_axis_type='datetime',
                       y_axis_label="Nett Sentiment (7 day mean)",
                       tools=[],
                       toolbar_location=None)
    # Setting range of y range
    line_plot.y_range = Range1d(-1, 1)

    # Adding Count range on the right
    line_plot.extra_y_ranges = {
        "count_range": Range1d(start=0,
                               end=sentiment_ts_sample_count.max() * 1.1)
    }
    secondary_axis = LinearAxis(y_range_name="count_range",
                                axis_label="Mentions")
    line_plot.add_layout(secondary_axis, 'right')

    sentiment_count_bars = line_plot.vbar(x="date",
                                          top="Count",
                                          width=pandas.Timedelta(days=0.75),
                                          color="orange",
                                          source=sentiment_ts_data,
                                          y_range_name="count_range")
    sentiment_line = line_plot.line(x="date",
                                    y="NettSentiment",
                                    color="blue",
                                    source=sentiment_ts_data,
                                    line_width=5)

    # Long Term sentiment baseline
    long_term_sentiment_span = Span(
        location=LONG_TERM_SENTIMENT,
        name="LongTermSentiment",
        dimension='width',
        line_color='red',
        line_dash='dashed',
        line_width=3,
    )
    line_plot.add_layout(long_term_sentiment_span)

    start_timestamp = sentiment_ts_data["date"].min()
    long_term_sentiment_label = Label(x=start_timestamp,
                                      y=LONG_TERM_SENTIMENT,
                                      x_offset=-10,
                                      y_offset=10,
                                      text='Sentiment Baseline',
                                      render_mode='css',
                                      border_line_color='white',
                                      border_line_alpha=0.0,
                                      angle=0,
                                      angle_units='deg',
                                      background_fill_color='white',
                                      background_fill_alpha=0.0,
                                      text_color='red',
                                      text_font_size='12pt')
    line_plot.add_layout(long_term_sentiment_label)

    hover_tool = HoverTool(renderers=[sentiment_line, sentiment_count_bars],
                           tooltips=tooltips,
                           formatters={
                               '@date': 'datetime',
                               'NettSentiment': 'printf'
                           })
    line_plot.add_tools(hover_tool)

    line_plot.xaxis.formatter = DatetimeTickFormatter(days="%Y-%m-%d")
    line_plot.yaxis.formatter = NumeralTickFormatter(format="0.[0]%")
    secondary_axis.formatter = NumeralTickFormatter(format="0.[0] a")

    line_plot.axis.axis_label_text_font_size = "12pt"
    line_plot.axis.major_label_text_font_size = "12pt"

    plot_html = file_html(line_plot, CDN, "Behavioural Sentiment Timeseries")

    return plot_html