Beispiel #1
0
def plot_event_occurrence(city, topic, years=[]):
    df = _load_city_topic(city, topic)
    df = df.loc[df.year.isin(years), ['local_time', 'weekday']]
    data = dict(day=df['weekday'].map(weekday_mapping),
                time=df['local_time'].dt.hour +
                df['local_time'].dt.minute / 60)
    source = ColumnDataSource(data)

    p = figure(plot_width=600, plot_height=300,
               y_range=list(reversed(DAYS)), x_range=[6, 24],
               title=f'{city} | {topic}')
    p.circle(x=jitter('time', width=1),
             y=jitter('day', width=0.6, range=p.y_range),
             source=source, alpha=0.1)

    hline = Span(location=2, dimension='width', line_width=0.5,
                 line_color='gray')
    p.renderers.extend([hline])

    p.ygrid.grid_line_color = None
    p.yaxis.major_tick_line_color = None
    p.xaxis.ticker = list(TIME.keys())
    p.xaxis.major_label_overrides = TIME
    p.xaxis.axis_label = 'Hour'
    p.yaxis.axis_label = 'Day'
    return p
Beispiel #2
0
    def get_data(self, element, ranges, style):
        dims = element.dimensions(label=True)

        xidx, yidx = (1, 0) if self.invert_axes else (0, 1)
        mapping = dict(x=dims[xidx], y=dims[yidx])
        data = {}

        if not self.static_source or self.batched:
            xdim, ydim = dims[xidx], dims[yidx]
            data[xdim] = element.dimension_values(xidx)
            data[ydim] = element.dimension_values(yidx)
            self._categorize_data(data, (xdim, ydim), element.dimensions())

        cdata, cmapping = self._get_color_data(element, ranges, style)
        data.update(cdata)
        mapping.update(cmapping)

        sdata, smapping = self._get_size_data(element, ranges, style)
        data.update(sdata)
        mapping.update(smapping)

        if 'angle' in style and isinstance(style['angle'], (int, float)):
            style['angle'] = np.deg2rad(style['angle'])

        if self.jitter:
            if self.invert_axes:
                mapping['y'] = jitter(dims[yidx], self.jitter,
                                      range=self.handles['y_range'])
            else:
                mapping['x'] = jitter(dims[xidx], self.jitter,
                                      range=self.handles['x_range'])

        self._get_hover_data(data, element)
        return data, mapping, style
Beispiel #3
0
    def get_data(self, element, ranges, style):
        dims = element.dimensions(label=True)

        xidx, yidx = (1, 0) if self.invert_axes else (0, 1)
        mapping = dict(x=dims[xidx], y=dims[yidx])
        data = {}

        if not self.static_source or self.batched:
            xdim, ydim = dims[xidx], dims[yidx]
            data[xdim] = element.dimension_values(xidx)
            data[ydim] = element.dimension_values(yidx)
            self._categorize_data(data, (xdim, ydim), element.dimensions())

        cdata, cmapping = self._get_color_data(element, ranges, style)
        data.update(cdata)
        mapping.update(cmapping)

        sdata, smapping = self._get_size_data(element, ranges, style)
        data.update(sdata)
        mapping.update(smapping)

        if 'angle' in style and isinstance(style['angle'], (int, float)):
            style['angle'] = np.deg2rad(style['angle'])

        if self.jitter:
            if self.invert_axes:
                mapping['y'] = jitter(dims[yidx], self.jitter,
                                      range=self.handles['y_range'])
            else:
                mapping['x'] = jitter(dims[xidx], self.jitter,
                                      range=self.handles['x_range'])

        self._get_hover_data(data, element)
        return data, mapping, style
Beispiel #4
0
def get_song_placement_graph(band_json, band, size):
    with open('data/song_position_dict.json') as f:
      song_position_dict = load(f)
    song_position_lists = song_position_dict[band]
    placement_df, top_songs = get_song_placement_df(band_json, song_position_lists)

    iqr_df, avg_iqr_placement = get_iqr_df(song_position_lists, top_songs)

    #Create color coding for placement
    years = placement_df['year'].values
    mapper = linear_cmap(field_name='year', palette=RdYlBu11, low=min(years), high=max(years))
    top_songs_w_av = ['Average IQR'] + top_songs[::-1]
    source_place = ColumnDataSource(placement_df)
    source_iqr = ColumnDataSource(iqr_df)
    top10_placement = figure(y_range=top_songs_w_av, title=band, frame_width=int(400*size),
                             plot_width=int(700*size), tooltips=[('Date','@date'), ('Show Placement','@hover')],
                             sizing_mode='stretch_both', toolbar_location=None
                             )
    top10_placement.circle(x='placement', y=jitter('song', width=0.4, range=top10_placement.y_range),
                           radius=0.01, fill_alpha=0.6, source=source_place, color=mapper
                           )
    top10_placement.hbar(y='Songs', left='Q1', right='Q3', source = source_iqr,
                         height = 0.4, color = yellow, fill_alpha=0.5
                         )
    color_bar = ColorBar(color_mapper=mapper['transform'], width=8, location=(0, 0))
    top10_placement.add_layout(color_bar, 'right')
    top10_placement.xaxis.ticker = [0, 0.5, 1]
    top10_placement.xaxis.major_label_overrides = {0: 'Start of Show', 0.5: 'Middle of Show', 1: 'End of Show', }
    top10_placement.circle(x=1,y=0)
    top10_placement.xaxis.axis_label = 'Placement of Top 10 Most Played Songs'
    return top10_placement, avg_iqr_placement
Beispiel #5
0
def swarmplot(x=None,
              y=None,
              data=None,
              width=500,
              height=500,
              p=None,
              hue_order=None,
              jitter_width=0.6,
              s=5,
              alpha=0.5,
              line_color='black',
              **plot_kw):

    if len(x) == 1:
        data['x'] = data[x]
    else:
        data['x'] = list(data[x].itertuples(index=False, name=None))

    if p is None:
        p = figure(x_range=FactorRange(*data['x'].unique()),
                   width=width,
                   height=height,
                   min_border=100,
                   x_axis_label=x[0],
                   y_axis_label=y)

    p.circle(x=jitter('x', width=jitter_width, range=p.x_range),
             y=y,
             line_color=line_color,
             source=data,
             size=s,
             alpha=alpha,
             **plot_kw)

    return p
Beispiel #6
0
def analysis(request):
    '''
    Render analysis page
    '''
    feature_name = request.GET.get('feature')
    feature_names = ["beds", "baths"]
    if feature_name == "baths":
        cats = list(set(House.objects.values_list('baths', flat=True)))
    else:
        feature_name = "beds"
        cats = list(set(House.objects.values_list('beds', flat=True)))
    rent = list(House.objects.values_list('rent', flat=True))
    g = list(House.objects.values_list(feature_name, flat=True))
    data = {'rent': rent, 'category': g}
    source = ColumnDataSource(data=data)
    cats = sorted(cats)
    p = figure(plot_width=800,
               plot_height=800,
               y_range=cats,
               title="Rent by Category")
    p.circle(x='rent',
             y=jitter('category', width=0.6, range=p.y_range),
             alpha=0.3,
             source=source)
    p.x_range.range_padding = 0
    p.ygrid.grid_line_color = None
    script, div = components(p)
    return render(
        request, "analysis.html", {
            'script': script,
            'div': div,
            'feature_names': feature_names,
            "current_feature_name": feature_name
        })
def boxplot_single(info, cmap, col1, col2=None, scatter_data=None):

    info['IQR'] = info.q3 - info.q1

    info['upper'] = np.min([info['max'], info.q3 + 1.5 * info.IQR], axis=0)
    info['lower'] = np.max([info['min'], info.q1 - 1.5 * info.IQR], axis=0)

    info['color'] = [cmap[f] for f in info[col1]]

    tooltips = []
    if scatter_data is not None:
        tooltips = scatter_data.drop(['y', col1], axis=1).columns
        tooltips = zip(tooltips, '@' + tooltips)

    p = figure(title=f"{col2} vs {col1}",
               background_fill_color="#efefef",
               plot_width=300,
               plot_height=400,
               tooltips=list(tooltips),
               x_range=info[col1].tolist())

    # stems
    p.segment(col1, 'upper', col1, 'q3', line_color="black", source=info)
    p.segment(col1, 'lower', col1, 'q1', line_color="black", source=info)

    # boxes
    p.vbar(x=col1,
           width=0.7,
           bottom='q2',
           top='q3',
           line_color="black",
           color='color',
           source=info)
    p.vbar(x=col1,
           width=0.7,
           bottom='q1',
           top='q2',
           line_color="black",
           color='color',
           source=info)

    if scatter_data is not None:
        scatter_data = scatter_data.sample(frac=1).groupby(col1).head(500)
        scatter_data['color'] = [cmap[x] for x in scatter_data[col1]]

        p.circle(x=jitter(col1, 0.2, range=p.x_range),
                 y='y',
                 line_color='black',
                 fill_color='color',
                 alpha=0.5,
                 source=scatter_data)

    # # whiskers (almost-0 height rects simpler than segments)
    # h = np.abs(info.q3).mean()
    # p.rect(x=col1, y='lower', width=0.2, height=0.01*h, color="black", source=info)
    # p.rect(x=col1, y='upper', width=0.2, height=0.01*h, color="black", source=info)

    p.xaxis.major_label_orientation = "vertical"

    return p
Beispiel #8
0
    def create(self):
        "add to doc"
        self._src = {i: ColumnDataSource(data = j) for i, j in self._data(None).items()}
        self._fig = self.figure(y_range   = Range1d, x_range = FactorRange())
        self._fig.grid[0].grid_line_alpha = self._theme.xgridalpha
        self._ref = LinearAxis(axis_label = self._theme.reflabel,
                               formatter  = NumeralTickFormatter(format = "0"))
        self._fig.add_layout(self._ref, 'right')

        jtr       = jitter("bead", range = self._fig.x_range, width = .75)
        self.addtofig(self._fig, "events", x = jtr, y = 'bases',
                      source = self._src["events"])
        self.addtofig(self._fig, "hpin",  x = "bead", y = 'bases', source = self._src["hpin"])
        rend = self.addtofig(self._fig, "peaks",  x = "bead", y = 'bases',
                             source = self._src["peaks"])
        hover = self._fig.select(HoverTool)
        if len(hover) > 0:
            hover = hover[0]
            hover.update(point_policy = self._theme.tooltippolicy,
                         tooltips     = self._theme.tooltips,
                         mode         = self._theme.tooltipmode,
                         renderers    = [rend])

        self.linkmodeltoaxes(self._fig)
        self._fig.yaxis.formatter = NumeralTickFormatter(format = self._theme.format)
        self._errors = PlotError(self._fig, self._theme)
        return self._fig
Beispiel #9
0
    def get_data(self, element, ranges, style):
        dims = element.dimensions(label=True)

        xidx, yidx = (1, 0) if self.invert_axes else (0, 1)
        mapping = dict(x=dims[xidx], y=dims[yidx])
        data = {}

        if not self.static_source:
            xdim, ydim = dims[xidx], dims[yidx]
            data[xdim] = element.dimension_values(xidx)
            data[ydim] = element.dimension_values(yidx)
            self._categorize_data(data, (xdim, ydim), element.dimensions())

        cdata, cmapping = self._get_color_data(element, ranges, style)
        data.update(cdata)
        mapping.update(cmapping)

        sdata, smapping = self._get_size_data(element, ranges, style)
        data.update(sdata)
        mapping.update(smapping)

        if self.jitter:
            axrange = 'y_range' if self.invert_axes else 'x_range'
            mapping['x'] = jitter(dims[xidx],
                                  self.jitter,
                                  range=self.handles[axrange])

        self._get_hover_data(data, element)
        return data, mapping, style
Beispiel #10
0
def plottingAllData(df, means, labels, indexes, param, colors):
    """
    Plots the data included in the dataframe "df" from liquid and solid grown cells
    """
    p = bokeh.plotting.figure(width=600,
                              height=600,
                              y_range=labels,
                              x_axis_type='linear',
                              x_axis_label='Fluorescence intensity',
                              title="Motor " + param +
                              " on solid vs liquid environement")
    for i, index in enumerate(indexes):
        p.circle(
            source=df.loc[index, :],
            x=param,
            y=jitter('Labels', width=0.3, range=p.y_range),
            color=colors[i],
            alpha=0.3,
            #legend = labelsAll[i]
        )
    p.circle(source=means,
             x=param,
             y='Labels',
             size=10,
             line_color='black',
             fill_color='white',
             legend="medians")
    p.add_tools(
        HoverTool(tooltips=[('Strain', '@{Strain}'),
                            ('Growth condition', '@{Growth}'),
                            (param, '@{' + param + '}'),
                            ('Biological replicate', '@{Bio_Rep}')], ))
    return p
    def plot_accidents_by_time_each_day(self, data, output_filename):
        output_path = "{}/{}.html".format(self.output_directory, output_filename)
        output_file(output_path)

        days_english = np.array(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"])
        p = figure(
            y_range=days_english.tolist(),
            x_axis_type="datetime",
            x_axis_label="time",
            toolbar_location=None,
            sizing_mode="stretch_both",
            aspect_ratio=self.aspect_ratio,
            tools="",
        )

        p.circle(
            x="DATA_HORA",
            y=jitter("DAY_ENGLISH", width=0.4, range=p.y_range),
            source=data,
            alpha=0.2,
        )

        p.xaxis[0].formatter.days = ["%Hh"]
        p.x_range.range_padding = 0
        p.ygrid.grid_line_color = None

        self.plots[output_filename] = p
        save(p)
Beispiel #12
0
def freqinpoem(poem_code, tokens):
    if tokens is None:
        tokens = ["אַ".decode('utf8')]

    words_v = tokens
    text = words(poems[poem_code][5])
    title = poems[poem_code][1]

    # make connection, format query
    cnx = mysql.connector.connect(**config)
    cursor = cnx.cursor()
    query = "SELECT name_y FROM poet WHERE name_e=\"" + poems[poem_code][
        3] + "\""
    cursor.execute(query)
    db_poet = cursor.fetchall()
    cnx.close()

    poet = db_poet[0][0]
    x = []
    y = []
    con = []
    for x_pos in range(len(text)):
        for y_pos in range(len(words_v)):
            if text[x_pos] == words_v[y_pos]:
                x.append(x_pos)
                y.append(words_v[y_pos])
                line = "..."
                for w in text[x_pos - 3:x_pos + 4]:
                    line += w + " "
                line += "..."
                con.append(line)

    hover = HoverTool(tooltips=[("Offset", "@x" + "/" +
                                 str(len(text))), ("Word",
                                                   "@y"), ("Context", "@con")])

    data = dict(x=x, y=y, con=con)
    src = ColumnDataSource(data)

    p = figure(plot_height=400,
               y_range=words_v,
               title="Dispersion for :" + title + " פֿון ".decode('utf8') +
               poet,
               tools="pan,wheel_zoom,box_zoom,save,reset",
               active_scroll="wheel_zoom")
    p.add_tools(hover)
    p.xaxis.axis_label = "Word Offset"
    p.yaxis.axis_label = "Search Word"
    p.x_range.range_padding = 0
    p.ygrid.grid_line_color = None
    p.circle(x='x',
             y=jitter('y', width=0.6, range=p.y_range),
             source=src,
             alpha=0.6,
             size=6,
             fill_color=Set2[8][0])

    return p
Beispiel #13
0
 def test_basic(self) -> None:
     t = bt.jitter("foo", width=0.5, mean=0.1, distribution="normal")
     assert isinstance(t, Field)
     assert t.field == "foo"
     assert isinstance(t.transform, Jitter)
     assert t.transform.width == 0.5
     assert t.transform.mean == 0.1
     assert t.transform.distribution == "normal"
     assert t.transform.range is None
Beispiel #14
0
 def test_defaults(self) -> None:
     t = bt.jitter("foo", width=0.5)
     assert isinstance(t, Field)
     assert t.field == "foo"
     assert isinstance(t.transform, Jitter)
     assert t.transform.width == 0.5
     assert t.transform.mean == 0
     assert t.transform.distribution == "uniform"
     assert t.transform.range is None
 def test_basic(self):
     t = bt.jitter("foo", width=0.5, mean=0.1, distribution="normal")
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0.1
     assert t['transform'].distribution == "normal"
     assert t['transform'].range is None
 def test_defaults(self):
     t = bt.jitter("foo", width=0.5)
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0
     assert t['transform'].distribution == "uniform"
     assert t['transform'].range is None
Beispiel #17
0
 def test_basic(self):
     t = bt.jitter("foo", width=0.5, mean=0.1, distribution="normal")
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0.1
     assert t['transform'].distribution == "normal"
     assert t['transform'].range is None
Beispiel #18
0
 def test_defaults(self):
     t = bt.jitter("foo", width=0.5)
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0
     assert t['transform'].distribution == "uniform"
     assert t['transform'].range is None
Beispiel #19
0
def prepare_plots3(target_vals,epoch, METRICSPATH):

    cfm_file = f"{METRICSPATH}/confusion-{epoch}.png"
    bok_file = f"{METRICSPATH}/ranking_{epoch}.html"
   

    classes, rankings, preds, pred_rank = [],[],[],[]
    
    for t_ in target_vals:
        cl_,ra_,pr_,em_ = t_
        classes.append(cl_)
        rankings.append(ra_)
        preds.append(pr_)
        pred_rank.append(em_)



    classes = np.squeeze(np.concatenate(classes))
    rankings = np.squeeze(np.concatenate(rankings))
    predictions = np.concatenate([softmax(p,axis=0) for p in preds])
    pred_rank = np.concatenate(pred_rank)
    
    activations = np.argmax(predictions,axis=1) 
    conf_mat = confusion_matrix(classes,activations)
    fig = plt.figure(figsize=[10,8])
    plot_confusion_matrix(conf_mat, classes=class_names, normalize=False,
                      title=f'Confusion matrix epoch {epoch}')
    plt.savefig(cfm_file,format="png")
    pil_image = fig2pil(fig)
    neptune.send_image('conf_mat', pil_image)


    df = pd.DataFrame(data={ 'tar': rankings, 'pred': pred_rank, 'class': classes})

    
    palette = magma(num_of_classes + 1)
    p = figure(plot_width=600, plot_height=800, title=f"Ranking by exercise, epoch {epoch}")
    p.xgrid.grid_line_color = None
    p.xaxis.axis_label = 'Target ranking'
    p.yaxis.axis_label = 'Predicted ranking'
    

    
    for cl in range(num_of_classes):
        if cl == 6:
            continue
        df2 = df.loc[df['class']==cl]
        p.circle(x=jitter('tar',0.3), y='pred', size=8, alpha=0.1, color=palette[cl], legend=class_names[cl], source=df2 )
        p.line(x='tar', y='pred', line_width=2, alpha=0.5, color=palette[cl],legend=class_names[cl], source=df2.groupby(by="tar").mean())
    p.legend.location = "top_left"
    p.legend.click_policy="hide"
    output_file(bok_file, title="Ranking by exercise")
    save(p)
    pil_image2 = get_screenshot_as_png(p)
    neptune.send_image('rank_distances', pil_image2)
Beispiel #20
0
 def test_with_range(self) -> None:
     r = FactorRange("a")
     t = bt.jitter("foo", width=0.5, mean=0.1, range=r)
     assert isinstance(t, Field)
     assert t.field == "foo"
     assert isinstance(t.transform, Jitter)
     assert t.transform.width == 0.5
     assert t.transform.mean == 0.1
     assert t.transform.distribution == "uniform"
     assert t.transform.range is r
     assert t.transform.range.factors == ["a"]
 def test_with_range(self):
     r = FactorRange("a")
     t = bt.jitter("foo", width=0.5, mean=0.1, range=r)
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0.1
     assert t['transform'].distribution == "uniform"
     assert t['transform'].range is r
     assert t['transform'].range.factors == ["a"]
Beispiel #22
0
def plot_jitter(data_frame):
    ratings = sorted(data_frame.rating.unique())
    jitter_plot = figure(plot_width=1600, plot_height=800,
                title="Application Rating Vs No. of Installations", y_axis_type='log')
    jitter_plot.xgrid.grid_line_color = None
    jitter_plot.xaxis[0].ticker = ratings
    jitter_plot.circle(x=jitter('rating', 0.4), y='installs', size=9, alpha=0.4, source=data_frame)
    jitter_plot.xaxis.axis_label = 'Ratings'
    jitter_plot.yaxis.axis_label = 'No. of Installations'
    output_file("./Data/jitter.html")
    show(jitter_plot)
    return True
Beispiel #23
0
 def test_with_range(self):
     r = FactorRange("a")
     t = bt.jitter("foo", width=0.5, mean=0.1, range=r)
     assert isinstance(t, dict)
     assert set(t) == {"field", "transform"}
     assert t['field'] == "foo"
     assert isinstance(t['transform'], Jitter)
     assert t['transform'].width == 0.5
     assert t['transform'].mean == 0.1
     assert t['transform'].distribution == "uniform"
     assert t['transform'].range is r
     assert t['transform'].range.factors == ["a"]
Beispiel #24
0
def build_trade_scatter(path, product_id, output_file=None, show=False):
    product_df = pd.read_csv(
        path,
        index_col=None,
        parse_dates=['server_datetime', 'exchange_datetime'])

    # Get the weekday and time
    product_df['weekday_name'] = product_df[
        'exchange_datetime'].dt.weekday_name
    product_df['time'] = product_df['exchange_datetime'].dt.time

    # Setting color based on buy/sell
    color_map = {'sell': C_SELL, 'buy': C_BUY}
    product_df['color'] = [color_map[entry] for entry in product_df['side']]

    # Days reversed so they will be in order top to bottom
    days = [
        'Sunday', 'Saturday', 'Friday', 'Thursday', 'Wednesday', 'Tuesday',
        'Monday'
    ]

    source = ColumnDataSource(product_df)

    tools = 'save,pan,box_zoom,xwheel_zoom,reset'
    p = bplot.figure(title='Trades Over Time',
                     tools=tools,
                     plot_width=800,
                     plot_height=300,
                     y_range=days,
                     active_scroll='xwheel_zoom',
                     x_axis_type='datetime',
                     background_fill_color=C_CHART_BG)

    p.circle(x='time',
             y=jitter('weekday_name', width=0.6, range=p.y_range),
             source=source,
             alpha=0.6,
             fill_color='color',
             line_color=None)

    p.xaxis[0].formatter.days = ['%Hh']

    p.x_range.range_padding = 0

    styles = {}
    _apply_figure_styles(p, **styles)
    if output_file:
        bplot.output_file(output_file)
        bplot.save(p)
    if show:
        bplot.show(p)
    return p
Beispiel #25
0
def interactive_scatterplot(pdata,
                            tooltip_cols=[
                                "x", "y", "dataset", "category", "frequency"
                            ]):
    output_notebook()

    p = figure(
        title="comparison",
        y_axis_type="log",
        x_axis_type="log",
        plot_width=800,
        plot_height=500,
        tools=[HoverTool(), PanTool(),
               BoxZoomTool(),
               ResetTool()],
        tooltips=", ".join(["@{}".format(col) for col in tooltip_cols]),
        #                "@x, @y, @dataset, @category, @query_string, @frequency",
        background_fill_color="#fafafa",
    )

    source = ColumnDataSource(pdata)

    p.circle(
        x=jitter("x", width=0.1),
        y=jitter("y", width=0.1),
        size=10,
        fill_color=make_color_map(pdata, "dataset"),
        line_color="black",
        source=source,
    )

    def url_tool(url_column1, url_column2):
        url = f"http://*****:*****@{url_column1}&other=@{url_column2}"
        taptool = TapTool()
        taptool.callback = OpenURL(url=url)
        return taptool

    p.add_tools(url_tool("session_path", "base_session_path"))
    show(p)
Beispiel #26
0
def plot_jitter2(data_frame):
    pricing = sorted(data_frame.price.unique())
    jitter_plot = figure(plot_width=1600, plot_height=800,
                         title="Application Rating Vs Price of Applications", y_axis_type='log')

    jitter_plot.xgrid.grid_line_color = "red"
    jitter_plot.xaxis[0].ticker = pricing
    jitter_plot.circle(x=jitter('price', 0.4), y='installs',
                       size=9, alpha=0.4, source=data_frame, color="red")
    jitter_plot.xaxis.axis_label = 'price'
    jitter_plot.yaxis.axis_label = 'No. of Installations'
    output_file("./Data/jitter2.html")
    show(jitter_plot)
    return True
Beispiel #27
0
def plot_games(data, model, features, **plot_kwargs):
    plot_kwargs.setdefault("x_axis_label", features[0])
    plot_kwargs.setdefault("y_axis_label", features[1])
    plot_kwargs.setdefault("tools", TOOLS)
    plot_kwargs.setdefault(
        "tooltips",
        [
            ("name", "@name"),
            ("year", "@year"),
            ("complexity", "@complexity"),
            ("time", "@min_time–@max_time minutes"),
            ("age", "@min_age+"),
        ],
    )

    plot = figure(**plot_kwargs)

    data["color"] = [
        "#193F4A" if kennerspiel else "#E30613" for kennerspiel in data.ksdj
    ]
    data["marker"] = np.where(
        model.predict(data[features]) == data.ksdj, "circle", "square")

    plot.scatter(
        source=data,
        x=features[0],
        y=jitter(features[1], width=0.25, distribution="normal"),
        color="color",
        marker="marker",
        # alpha=0.9,
        size=8,
    )

    w1 = model.coef_[0, 0]
    w2 = model.coef_[0, 1]
    b = model.intercept_[0]
    slope = Slope(
        gradient=-w1 / w2,
        y_intercept=-b / w2,
        line_color="black",
        line_dash="dashed",
        line_width=2,
    )
    plot.add_layout(slope)

    return plot
Beispiel #28
0
def get_timeline_plot(source, toolbox, names, y, title):
    "Plot the observations through time accross given y"
    p = figure(plot_width=1000,
               plot_height=300,
               y_range=names,
               x_axis_type='datetime',
               title=title,
               tools=toolbox)

    p.circle(x='date',
             y=jitter(y, width=0.6, range=p.y_range),
             source=source,
             alpha=0.3,
             line_color="colors_case",
             fill_color="colors_case")

    p.toolbar.active_scroll = p.select_one(WheelZoomTool)
    return p
Beispiel #29
0
def update():
    df = get_publish_table(y_axis.value)
    p.y_range.factors = df[y_axis.value].dropna().unique().tolist()
    p.circle(x='x',
             y=jitter('y', width=0.2, range=p.y_range),
             source=source,
             alpha=0.3)
    p.xaxis[0].formatter.days = ['%Hh']
    p.x_range.range_padding = 0
    p.ygrid.grid_line_color = None
    p.xaxis.axis_label = x_axis.value
    p.yaxis.axis_label = y_axis.value
    p.title.text = "%d items selected" % len(df)
    source.data = dict(
        x=df[x_axis.value],
        y=df[y_axis.value],
        # headline=df['headline'],
    )
Beispiel #30
0
    def plot(self):
        plot = figure(
            title="Requests by Time of Day",
            tools="",
            toolbar_location=None,
            sizing_mode="scale_width",
            # plot_width=800,
            plot_height=300,
            y_range=list(reversed(DAYS)),
            x_axis_type="datetime",
        )

        plot.circle(
            x="time",
            y=jitter("day", width=0.6, range=plot.y_range),
            source=ColumnDataSource(self.data()),
            alpha=0.3,
        )

        plot.xaxis.formatter.days = ["%Hh"]
        plot.x_range.range_padding = 0
        plot.ygrid.grid_line_color = None
        return plot
Beispiel #31
0
def plot_read_hash_abundances(dfm: pd.DataFrame, ofname: Path) -> None:
    """Plot distribution of unique read counts.

    :param dfm:  pd.DataFrame containing one row per sample/hash combination
    :param ofname:  Path to output file for figure
    """
    # Set data sources
    dfm["read_hash"] = dfm["read_hash"].str.slice(0, 6)
    source = ColumnDataSource(dfm)
    categories = sorted(set(source.data["read_hash"]))
    colours = factor_cmap("read_hash",
                          palette=Category20[len(categories)],
                          factors=categories)

    # Render abundances
    tooltips = [("sample", "@sample_name"), ("abundance", "@abundance")]
    fig = figure(
        x_range=categories,
        plot_width=100 * len(categories),
        plot_height=600,
        title="Unique Read Abundances By Hash",
        y_axis_type="log",
        tooltips=tooltips,
    )
    fig.scatter(
        x=jitter("read_hash", width=0.4, range=fig.x_range),
        y="abundance",
        source=source,
        size=10,
        alpha=0.6,
        hover_fill_alpha=1,
        fill_color=colours,
    )

    # Save figure
    output_file(ofname)
    save(fig)
def analysis(request):
    feature_name = request.GET.get('feature')
    feature_names = ["bedrooms", "bathrooms", "room_type_category"]
    data_path = './new_york.json'
    json_data = open(data_path)
    data = json.loads(json_data.read())
    prices = []
    category = []
    if not feature_name:
        feature_name = 'bedrooms'
    for element in data:
        if element[feature_name] is not None:
            prices.append(element['price'])
            category.append(element[feature_name])
    json_data.close()
    data = {'prices': prices, 'category': category}
    source = ColumnDataSource(data=data)
    cats = list(set(category))
    cats = [str(c) for c in sorted(cats)]
    p = figure(plot_width=800,
               plot_height=800,
               y_range=cats,
               title="Rent by Category")
    p.circle(x='prices',
             y=jitter('category', width=0.6, range=p.y_range),
             alpha=0.3,
             source=source)
    p.x_range.range_padding = 0
    p.ygrid.grid_line_color = None
    script, div = components(p)
    return render(
        request, "analysis.html", {
            'script': script,
            'div': div,
            'feature_names': feature_names,
            "current_feature_name": feature_name
        })
Beispiel #33
0
def box_plot(x,y,cl_ar,bok_file,epoch):
    class_names = ['squat', 'deadlift', 'pushups', 'pullups', 'wallpushups', 'lunges', 'other', 'cleanandjerk']
    num_of_classes = len(class_names)
    df = pd.DataFrame(data={ 'tar': x, 'pred': y, 'class': cl_ar})
    palette = magma(num_of_classes + 1)
    p = figure(plot_width=600, plot_height=800, title=f"Ranking by exercise, epoch {epoch}")
    p.xgrid.grid_line_color = None
    p.xaxis.axis_label = 'Target ranking'
    p.yaxis.axis_label = 'Predicted ranking'
    

    
    for cl in range(num_of_classes):
        if cl == 6:
            continue
        df2 = df.loc[df['class']==cl]
        p.circle(x=jitter('tar', 0.5), y='pred', size=8, alpha=0.1, color=palette[cl], legend=class_names[cl], source=df2 )
        p.line(x='tar', y='pred', line_width=2, alpha=0.5, color=palette[cl], source=df2.groupby(by="tar").mean())
    p.legend.location = "top_left"
    p.legend.click_policy="hide"
    output_file(bok_file, title="Ranking by exercise")
    save(p)
    pil_image2 = get_screenshot_as_png(p)
    neptune.send_image('rank_distances', pil_image2)
Beispiel #34
0
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.sampledata.commits import data
from bokeh.transform import jitter

output_file("bars.html")

DAYS = ['Sun', 'Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon']

source = ColumnDataSource(data)

p = figure(plot_width=800,
           plot_height=300,
           y_range=DAYS,
           x_axis_type='datetime',
           title="Commits by Time of Day (US/Central) 2012—2016")

p.circle(x='time',
         y=jitter('day', width=0.6, range=p.y_range),
         source=source,
         alpha=0.3)

p.xaxis[0].formatter.days = ['%Hh']
p.x_range.range_padding = 0
p.ygrid.grid_line_color = None

show(p)
Beispiel #35
0
from bokeh.layouts import row
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.autompg import autompg
from bokeh.transform import jitter

source = ColumnDataSource(autompg)

TOOLS = "save,box_select,lasso_select"

s1 = figure(tools=TOOLS, plot_width=400, plot_height=400,
            x_axis_label='# Cylinders', y_axis_label='MPG')

s1.circle(jitter('cyl', 0.5), 'mpg', source=source)

s2 = figure(tools=TOOLS, plot_width=400, plot_height=400,
            x_axis_label='Acceleration', y_axis_label='MPG')

# linked brushing is expressed by sharing data sources between renderers
s2.circle('accel', 'mpg', source=source)

output_file("linked_brushing.html", title="linked_brushing.py example")

show(row(s1,s2))
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.sampledata.commits import data
from bokeh.transform import jitter

output_file("bars.html")

DAYS = ['Sun', 'Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon']

source = ColumnDataSource(data)

p = figure(plot_width=800, plot_height=300, y_range=DAYS, x_axis_type='datetime',
           title="Commits by Time of Day (US/Central) 2012—2016")

p.circle(x='time', y=jitter('day', width=0.6, range=p.y_range),  source=source, alpha=0.3)

p.xaxis[0].formatter.days = ['%Hh']
p.x_range.range_padding = 0
p.ygrid.grid_line_color = None

show(p)
Beispiel #37
0
from bokeh.layouts import column
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.autompg import autompg
from bokeh.transform import jitter

years = sorted(autompg.yr.unique())

p1 = figure(plot_width=600, plot_height=300, title="Years vs mpg without jittering")
p1.xgrid.grid_line_color = None
p1.xaxis[0].ticker = years
p1.circle(x='yr', y='mpg', size=9, alpha=0.4, source=autompg)

p2 = figure(plot_width=600, plot_height=300, title="Years vs mpg with jittering")
p2.xgrid.grid_line_color = None
p2.xaxis[0].ticker = years
p2.circle(x=jitter('yr', 0.4), y='mpg', size=9, alpha=0.4, source=autompg)

output_file("jitter.html")

show(column(p1, p2))