Ejemplo n.º 1
0
    def create_barchart(self, group_df, group_name, substrate):
        '''Calculates mean if all labels are equivalent'''
        labels = ["Batch", "Wafer No.", "HM location", "Test structure"]
        labels.remove(self.sort_parameter)
        innermost_groups = group_df.groupby(labels)
        r_mean = innermost_groups["Resistivity"].mean(
        )  ##calculate the error that happens here
        '''creates chart data and BarChart Object'''
        keys = ["/".join(key) for key in innermost_groups.groups.keys()]
        chart_data = [(label, resistance)
                      for label, resistance in zip(keys, r_mean)]
        labels = "/".join(labels)
        chart = hv.Bars(chart_data, hv.Dimension(labels), "Resistivity")
        '''calculates std_mean with error propagation'''
        std_mean_l = []
        for group in innermost_groups:  #each group corresponds to a bar
            std_mean2 = 0
            for i in group[1]["Standard deviation"]:
                std_mean2 += (i / len(group[1]["Standard deviation"]))**2
            std_mean2 = np.sqrt(std_mean2)
            std_mean_l.append(std_mean2)
        '''calculate error of r_mean '''
        r_mean_error = []
        for index, group in enumerate(innermost_groups):
            diff_from_mean = 0
            group_mean = r_mean[index]
            for i in group[1]["Resistivity"]:
                if len(group[1]["Resistivity"]) > 1:
                    diff_from_mean += ((i - group_mean)**2 /
                                       (len(group[1]["Resistivity"]) - 1))
            diff_from_mean = np.sqrt(diff_from_mean)
            r_mean_error.append(diff_from_mean)

        error = [max(i, j) for i, j in zip(r_mean_error, std_mean_l)]
        '''creates errorbars and configures the plot'''
        error_bars = hv.ErrorBars((keys, r_mean, error))
        error_bars.opts(line_width=5)
        chart = chart * error_bars

        chart.opts(title=substrate + " " + group_name,
                   **self.config["Van_der_Pauw"].get("General", {}),
                   ylim=(0, self.limits[substrate]),
                   xrotation=45)

        if self.PlotDict["All"] is None:
            self.PlotDict["All"] = chart
        else:
            self.PlotDict["All"] = self.PlotDict["All"] + chart
Ejemplo n.º 2
0
Archivo: app.py Proyecto: herrfz/corona
def plot_country_recovery_rates(country):
    recovered_country = recovered.loc[:, (slice(None), country)].sum(axis=1)
    recovered_country_rate = ((
        (recovered_country / recovered_country.shift() - 1) * 100).replace(
            [np.inf, -np.inf], np.nan).dropna())
    return (hv.Bars([
        (i, recovered_country_rate.loc[i])
        for i in recovered_country_rate.index
    ]).redim(x='Date',
             y='Percent').opts(height=400,
                               width=700,
                               fontsize={'xticks': 6},
                               xrotation=90,
                               ylim=(0, 100),
                               title='Day-over-Day Growth of Recovered Cases',
                               tools=[rhover],
                               show_frame=False))
Ejemplo n.º 3
0
def get_daily_increment(complete_df):
    df = complete_df.copy()

    df = df.groupby('Fecha').sum()[['Casos', 'Fallecidos']]
    df.reset_index(inplace=True)
    df.Fecha = df.loc[:, 'Fecha'].dt.strftime('%d-%m')

    key_columns = ['Casos', 'Fallecidos']
    colors = ['#cf3e3e', '#000000']
    plots = []
    for column, color in zip(key_columns, colors):
        total = df[column].values

        after = total[1:]
        before = total[:-1]
        increment = after - before

        # over total
        increment = np.append(0, increment)
        total = np.where(total == 0, 1, total)  # preventing divisions with 0
        increment_per = (increment / total) * 100
        df[f'Incremento porcentual en {column.lower()}'] = np.round(
            increment_per, 2)

        #         # plot
        bars = hv.Bars(df,
                       kdims=['Fecha'],
                       vdims=f'Incremento porcentual en {column.lower()}',
                       label=f'Incremento porcentual en {column.lower()}')
        bars.opts(width=width,
                  height=height,
                  color=color,
                  xrotation=90,
                  invert_xaxis=False,
                  shared_axes=False,
                  tools=['hover'],
                  show_legend=True,
                  show_grid=True,
                  title='\nIncremento porcentual en {}'.format(column.lower()),
                  margin=(10, 0, 0, 0))
        plots.append(bars)

    layout = plots[0] + plots[1]
    # layout.opts(tabs=True)

    return layout
Ejemplo n.º 4
0
    def plot_cpu_frequency_transitions(self,
                                       cpu: CPU,
                                       pct: bool = False,
                                       domain_label: bool = False):
        """
        Plot frequency transitions count of the specified CPU

        :param cpu: The CPU to genererate the plot for
        :type cpu: int

        :param pct: Plot frequency transitions in percentage
        :type pct: bool

        :param domain_label: If ``True``, the labels will mention all CPUs in
            the domain, rather than the CPU passed.
        :type domain_label: bool
        """

        df = self.df_cpu_frequency_transitions(cpu)

        if pct:
            df = df * 100 / df.sum()

        ylabel = 'Transitions share (%)' if pct else 'Transition count'

        if domain_label:
            domains = self.trace.plat_info['freq-domains']
            rev_domains = {
                cpu: sorted(domain)
                for domain in domains for cpu in domain
            }
            name = ', '.join(map(str, rev_domains[cpu]))
            title = f'Frequency transitions of CPUs {name}'
        else:
            title = f'Frequency transitions of CPU{cpu}'

        if not df.empty:
            return hv.Bars(df['transitions']).options(
                title=title,
                xlabel='Frequency (Hz)',
                ylabel=ylabel,
                invert_axes=True,
            )
        else:
            return _hv_neutral()
Ejemplo n.º 5
0
def get_plot_barh(df, title):
    """Return a bar plot with the data and the title

    :param data_df: dataframe with the data.
    :param title: title for the plot.
    :returns: A plot (bokeh plot).
    :rtype: bokeh plot.
    """
    # Prepare to visualize
    kdims = [('alg', 'Algorithm'), ('category', 'Category'),
             ('ranking', 'Ranking')]
    # Plot the bar
    fields = ['alg', 'category', 'ranking']
    data_df = df[fields].sort_values(['alg'])
    data = [tuple(row) for row in data_df.values]
    options = "Bars [tools=['hover'] stack_index=1 color_index=1 show_legend=False xrotation=90]"
    bar = hv.Bars(data, kdims[:2], kdims[2], label=title)
    return bar.opts(options)
Ejemplo n.º 6
0
Archivo: app.py Proyecto: herrfz/corona
def plot_death_rate(country):
    confirmed_country = confirmed.loc[:, (slice(None), country)].sum(axis=1)
    recovered_country = recovered.loc[:, (slice(None), country)].sum(axis=1)
    death_country = death.loc[:, (slice(None), country)].sum(axis=1)
    death_country_rate = (
        death_country /
        (confirmed_country + recovered_country + death_country) * 100).replace(
            [np.inf, -np.inf], np.nan).dropna()
    return (hv.Bars([
        (i, death_country_rate.loc[i]) for i in death_country_rate.index
    ]).redim(x='Date', y='Percent').opts(height=400,
                                         width=700,
                                         fontsize={'xticks': 6},
                                         xrotation=90,
                                         ylim=(0, 15),
                                         title='Death Rate (% of infected)',
                                         tools=[rhover],
                                         show_frame=False))
Ejemplo n.º 7
0
def plot_label_bars(label_df, max_x=10):
    bar_list = list()

    for col in label_df.columns:

        if label_df[col].nunique() > max_x:
            continue

        label_names = label_df.groupby([col]).nunique().index.values
        label_counts = label_df.groupby([col]).count().max(axis=1).values

        new_bar = hv.Bars(zip(label_names, label_counts),
                          kdims=[col],
                          vdims=["count"],
                          group='Label Counts',
                          label=col)

        bar_list.append(new_bar)

    return hv.Layout(bar_list)
Ejemplo n.º 8
0
def plot_segregation(adata, save=False, filename=None):
    """Plot gabaergic and glutamaterig cell populations"""
    import holoviews as hv
    from holoviews import opts
    import pandas as pd
    hv.extension("matplotlib")

    df = pd.DataFrame(adata.uns["ligands"]).loc[["GABA", "L-glutamic acid"
                                                 ]].stack().reset_index()
    df.columns = ["ligand", "cluster", "value"]
    df = df.sort_values(by="cluster", axis=0)

    opts.defaults(
        opts.Bars(stacked=True,
                  xrotation=90,
                  legend_position="right",
                  ylabel="Ligand score"))
    bars = hv.Bars(df, kdims=["cluster", "ligand"])
    if save is True:
        hv.save(bars, filename)
    return bars
Ejemplo n.º 9
0
def closeness(party, graph, info, fc_info, centrality_function, show_yaxis):
    closeness_df = _get_closeness(graph, info, fc_info,
                                  centrality_function).sort_values("closeness")
    closeness_df["index"] = closeness_df.index.values
    columns = ["closeness", "selected", "FullName", "GroupNameEN"]
    group = fc_info["Group"].iloc[0]
    width = len(closeness_df) * 10
    opts = CLOSENESS_OPTS.copy()
    if show_yaxis:
        opts["yaxis"] = True
        opts["ylabel"] = "Harmonic Centrality"
    return hv.Bars(closeness_df,
                   kdims=["index"],
                   vdims=columns,
                   label=party + " Centrality").opts(
                       width=width,
                       cmap={
                           0: metadata.GROUP_COLOR[group],
                           1: "pink"
                       },
                       **opts)
Ejemplo n.º 10
0
    def layout_vis(stock):
        perd = '1d'
        end_realdata =  datetime.now().strftime("%Y") + '-' + \
                        datetime.now().strftime("%m") + '-'  + datetime.now().strftime("%d")

        start_date = (datetime.now() - timedelta(days=5))
        start_traindateD = start_date.strftime("%Y") + '-' + \
                           start_date.strftime("%m") + '-'  + start_date.strftime("%d")

        aord = DataAccess.data_auto_reader('^AORD', start_traindateD,
                                           end_realdata, perd)
        nikkei = DataAccess.data_auto_reader('1360.T', start_traindateD,
                                             end_realdata, perd)
        hsi = DataAccess.data_auto_reader('^HSI', start_traindateD,
                                          end_realdata, perd)

        daxi = DataAccess.data_auto_reader('DAX', start_traindateD,
                                           end_realdata, perd)
        cac40 = DataAccess.data_auto_reader('^FCHI', start_traindateD,
                                            end_realdata, perd)

        aord['Diff_price'] = aord.iloc[-1]['Close'] - aord.iloc[-1]['Open']
        hsi['Diff_price'] = hsi.iloc[-1]['Close'] - hsi.iloc[-1]['Open']
        nikkei[
            'Diff_price'] = nikkei.iloc[-1]['Close'] - nikkei.iloc[-1]['Open']

        data = [('aord', aord.iloc[-1]['Diff_price']),
                ('hsi', hsi.iloc[-1]['Diff_price']),
                ('nikkei', nikkei.iloc[-1]['Diff_price'])]

        hv_asia_bar = hv.Bars(
            data,
            hv.Dimension('Asian Market'),
            'Price Diff',
            label=aord.iloc[-1]['Date'].strftime("%Y-%m-%d")).opts(height=600,
                                                                   width=700)

        return hv_asia_bar
Ejemplo n.º 11
0
def create_interactive_plot(data_dispatch, data_bars):
    """

    """
    dispatch_hmap = hv.HoloMap(
        {(i, k): hv.Area.stack(
            hv.Overlay(
                [hv.Area(data_dispatch[k, i, :, j]) for j in range(n_stack)]))
         for i in range(n_i) for k in range(n_k)},
        kdims=['price pv', 'price wind'])

    bar_hmap = hv.HoloMap(
        {(i, k): hv.Bars(data_bars, hv.Dimension('Technology'),
                         'Installed capacity')
         for i in range(n_i) for k in range(n_k)},
        kdims=['price pv', 'price wind'])

    layout = hv.Layout(dispatch_hmap + bar_hmap).cols(1)

    ## https://github.com/ioam/holoviews/issues/1819
    renderer = hv.renderer('bokeh')

    # Using renderer save
    renderer.save(dispatch_hmap + bar_hmap, 'interactive_modeling')
Ejemplo n.º 12
0
    def precipitation(self, lon, lat):
        """Creates an **holoviews.Bars** object for precipitation.

        Parameters
        ----------
        lon : int or float
            The longitutde of the point.

        lat : int or float

        Raises
        ------
        ValueError
            If either longitude or latitude or both are out of bounds.

        See Also
        --------
        out_of_bounds : Checks if longitude and latitude are out of bounds.

        """
        out_of_bounds(lon, lat, 'ClimvisHVPlot.precipitation')
        self.reinitialize(lon, lat, self._overlay)
        return hv.Bars(annual_cycle_for_hv(
            lon, lat, variable='pre'), ).opts(tools=['hover'])
Ejemplo n.º 13
0
def figure_filter_class(index, weights):
    """Bar chart visualizing filter class composition"""
    data = pd.DataFrame({"Weight": weights}).rename_axis(index=index)
    return pn.pane.HoloViews(hv.Bars(data), sizing_mode="stretch_width")
Ejemplo n.º 14
0
def barchart(x, **kwargs):
    return hv.Bars(zip(range(x.min(),
                             x.max() + 1),
                       np.bincount(x)[x.min():]), **kwargs)
Ejemplo n.º 15
0
def get_outlier_analysis(batches, output_directory, filename='ttmap'):
      
    # plot the number of modified genes by control sample 
    if batches == []:
        batches = ['All']
    
    total_number_of_batches = range(len(batches))

    table_with_all_samples = pd.DataFrame({})

    for batch in total_number_of_batches:
        path_to_file = os.path.join(output_directory, filename + 'batch' +
                                    str(batch) + '_na_numbers_per_col.txt')

        dataset = pd.read_csv(path_to_file, header=0, index_col=0, sep='\t')
        dataset['Batches'] = [batches[batch]] * dataset.shape[0]
        dataset['Samples'] = list(dataset.index)

        table_with_all_samples = pd.concat([table_with_all_samples, dataset])

    table_with_all_samples.columns = ['Counts', 'Batches', 'Samples']

    key_dimensions = [('Samples', 'Sample')]
    value_dimensions = [('Counts', '# modified genes'), ('Batches', 'Batch')]

    viridis_cmap = process_cmap("Viridis", provider="bokeh", ncolors=len(batches))
    
    number_modified_genes = hv.Bars(table_with_all_samples, key_dimensions, value_dimensions).opts(tools=['hover'],
                                                                                   color='Batches',
                                                                                   cmap=viridis_cmap,
                                                                                   xticks = 0,
                                                                                   legend_position='top_left',
                                                                                   width = 500,
                                                                                   responsive = True
                                                                                  )
    
    # each gene is modified in x control samples. The plot below shows
    # the frequency of the percentage of corrected values (by samples) per
    # gene

    grid_corrected_genes = pn.GridSpec(sizing_mode='stretch_both', width=500)
    length_in_grid = np.int(np.ceil(np.float(len(batches))/np.float(3)))
    
    for counter, batch in enumerate(total_number_of_batches):
        path_to_file = os.path.join(output_directory, filename + 'batch' +
                                    str(batch) + '_na_numbers_per_row.txt')

        dataset = pd.read_csv(path_to_file, header=0, index_col=0, sep='\t')
 
        if dataset.shape[1] == 1:
            dataset.columns = ['Frequency']
        else:
            dataset.columns = ['Frequency', 'Other']

        frequencies, edges = np.histogram(dataset['Frequency'], 4, range=(0,1))
        
        histogram_frequencies = hv.Histogram((edges, frequencies), extents = (0,0,1,None)).opts(xlim=(0,1),
                                                                        responsive=True,
                                                                        tools=['hover'],
                                                                        hooks=[fix_x_axis],
                                                                        width = 220,
                                                                        title = batches[batch],
                                                                        xlabel = '% of corrected genes',
                                                                       )
        
        index_column = np.unravel_index(counter, (length_in_grid, 3))

        grid_corrected_genes[index_column[0], index_column[1]] = histogram_frequencies
    
    grid_corrected_genes[length_in_grid, :] = number_modified_genes
    
    return grid_corrected_genes 
Ejemplo n.º 16
0
# n keywords per book count
vals, counts = np.unique(ndfIDF['n_keywords'], return_counts=True)
tagcounts = pd.DataFrame({'n_keywordsPerBook': vals, 'count': counts})
tagcounts['pct'] = tagcounts['count'] / tagcounts['count'].sum()

#%%  create, save, display histograms for keywords, clusters, and keywordsPerBook

print('make, display, save keyword and concept histograms')

kwdBars = hv.Bars(tags_df, 'keywords', 'count').options(
    title_format='Keywords',
    labelled=['y'],
    color=hv.Cycle(values=Colors),
    color_index='keywords',
    #invert_axes=True, invert_yaxis=True,
    width=1200,
    height=400,
    tools=['hover'],
    xrotation=60,
    show_legend=False,
    show_grid=True)

conceptBars = hv.Bars(concepts_df, 'concepts', 'count').options(
    title_format='Concepts',
    labelled=['y'],
    color=hv.Cycle(values=Colors),
    color_index='concepts',
    #invert_axes=True, invert_yaxis=True,
    width=1200,
    height=300,
    tools=['hover'],
Ejemplo n.º 17
0
import pandas as pd
import holoviews as hv
%load_ext holoviews.ipython
df = pd.read_csv('data.csv')
bars = []
time = df['Year'].unique()
for t in time:
    bar = hv.Bars(df[df['Year']==t])
    bars.append((t,bar))
hmap = hv.HoloMap(bars,'Year').opts(aspect=1, fig_inches=6)
res = hv.output(hmap, holomap='gif', fps=3)
Ejemplo n.º 18
0
def seriesToHistogram(data,
                      fileName='histogram',
                      graphTitle='Distribution',
                      sortedAscending=True,
                      logScale=False,
                      xlbl='Value',
                      ylbl='Frequency'):
    data2 = data.replace(' ', np.nan)
    data2.dropna(inplace=True)
    # data2.sort_values(inplace=True)
    try:
        histData = pd.to_numeric(data2, errors='raise')
        numericData = True
    except:
        histData = data2
        numericData = False
    if numericData:
        # frequencies, edges = np.histogram(gpas, int((highest - lowest) / 0.1), (lowest, highest))

        dataList = histData.tolist()
        frequencies, edges = np.histogram(dataList,
                                          (int(math.sqrt(len(dataList))) if
                                           (len(dataList) > 30) else
                                           (max(len(dataList) // 3, 1))),
                                          (min(dataList), max(dataList)))
        #print('Values: %s, Edges: %s' % (frequencies.shape[0], edges.shape[0]))

        if logScale:
            frequencies = [
                math.log10(freq) if freq > 0 else freq for freq in frequencies
            ]
            ylbl += ' (log 10 scale)'
        histo = hv.Histogram((edges, frequencies))
        histo.opts(
            opts.Histogram(xlabel=xlbl,
                           ylabel=ylbl,
                           title=graphTitle,
                           fontsize={
                               'title': 40,
                               'labels': 20,
                               'xticks': 20,
                               'yticks': 20
                           }))
        subtitle = 'mean: ' + str(round(sum(dataList) / len(dataList),
                                        3)) + ', n = ' + str(len(dataList))
        hv.output(size=250)
        graph = hv.render(histo)
        graph.add_layout(
            Title(text=subtitle,
                  text_font_style="italic",
                  text_font_size="30pt"), 'above')
        output_file(outDir + fileName + '.html', mode='inline')
        save(graph)
        show(graph)
        # JH: Adds some specific display components when not in a graphical program.
        # JH: Consider a separate function for the two cases.
        if not edmApplication:
            hv.output(size=300)
            histo.opts(toolbar=None)
            graph = hv.render(histo)
            graph.add_layout(
                Title(text=subtitle,
                      text_font_style="italic",
                      text_font_size="30pt"), 'above')
            export_png(graph, filename=outDir + fileName + '.png')
    else:
        barData = histData.value_counts(dropna=False)
        dictList = sorted(zip(barData.index, barData.values),
                          key=lambda x: x[sortedAscending])
        # print(dictList)
        bar = hv.Bars(dictList)
        bar.opts(opts.Bars(xlabel=xlbl, ylabel=ylbl, title=graphTitle))
        subtitle = 'n = ' + str(len(dictList))
        hv.output(size=250)
        graph = hv.render(bar)
        graph.add_layout(
            Title(text=subtitle,
                  text_font_style="italic",
                  text_font_size="30pt"), 'above')
        output_file(outDir + fileName + '.html', mode='inline')
        save(graph)
        show(graph)
        # JH: Consider a bool exportPng=True when calling from outside edmAppliation
        if not edmApplication:
            hv.output(size=300)
            bar.opts(toolbar=None)
            graph2 = hv.render(bar)
            graph2.add_layout(
                Title(text=subtitle,
                      text_font_style="italic",
                      text_font_size="30pt"), 'above')
            export_png(graph2, filename=outDir + fileName + '.png')
    hv.output(size=125)
Ejemplo n.º 19
0
def plot_pozos_tipo():


    dims_eur_baja = dict(kdims='mes', vdims=['EUR_baja_L','EUR_baja_H'])
    env_eur_baja = hv.Area(perfil, label='EUR Baja', **dims_eur_baja)
    env_eur_baja.opts(alpha=0.3,
                      color='red',
                      fontscale=1.5)

    linea_eur_baja = hv.Curve(perfil.EUR_baja_M)
    linea_eur_baja.opts(color='red',
                        line_dash='dotted')

    dims_eur_media = dict(kdims='mes', vdims=['EUR_media_L','EUR_media_H'])
    env_eur_media= hv.Area(perfil, label='EUR Media', **dims_eur_media)
    env_eur_media.opts(alpha=0.3,
                       color='blue',
                       fontscale=1.5)

    linea_eur_media = hv.Curve(perfil.EUR_media_M)
    linea_eur_media.opts(color='blue',
                         line_dash='dotted')

    dims_eur_alta = dict(kdims='mes', vdims=['EUR_alta_L','EUR_alta_H'])
    env_eur_alta = hv.Area(perfil, label='EUR Alta', **dims_eur_alta)
    env_eur_alta.opts(alpha=0.3,
                      color='green',
                      fontscale=1.5)

    linea_eur_alta = hv.Curve(perfil.EUR_alta_M)
    linea_eur_alta.opts(color='green',
                        line_dash='dotted')

    elementos_tabla=dict(indice=resumen.index[6:13], valores=resumen[6:13])

    tabla_resumen = hv.Table(elementos_tabla,'indice','valores')
    tabla_resumen.opts(height=500,fontscale=20)

    plot_eur = env_eur_baja * linea_eur_baja * env_eur_media * linea_eur_media * env_eur_alta * linea_eur_alta
    plot_eur.opts(legend_position='top_left')

    elementos_tipos = dict(tipo=pd.unique(tipos.tipo), numero=tipos.tipo.value_counts())
    plot_tipos = hv.Bars(elementos_tipos,'tipo','numero')
    plot_tipos.opts(color='tipo',
                    cmap='Set1',
                    fontscale=1.5)
                    #fill_color=factor_cmap('tipo', palette=Spectral6, factors=elementos_tipos['tipo']))

    layout = plot_eur + plot_tipos  + tabla_resumen

    fig1 = hv.render(layout)

    hv.output(layout, backend='bokeh', fig='html', size=200)
    hv.save(layout, 'resumen_produccion.html')


    dims_baja = dict(kdims='mes', vdims=['baja_L','baja_H'])
    env_baja = hv.Area(perfil, label='Envolvente', **dims_baja)
    env_baja.opts(alpha=0.3,color='red',fontscale=1.5,title='Perfil BAJA Qoi')

    linea_baja = hv.Curve(perfil.baja_M,label='P50')
    linea_baja.opts(color='red',line_dash='dotted')

    dims_media = dict(kdims='mes', vdims=['media_L','media_H'])
    env_media= hv.Area(perfil, label='Envolvente', **dims_media)
    env_media.opts(alpha=0.3,color='blue',fontscale=1.5,title='Perfil MEDIA Qoi')

    linea_media = hv.Curve(perfil.media_M,label='P50')
    linea_media.opts(color='blue',line_dash='dotted')

    dims_alta = dict(kdims='mes', vdims=['alta_L','alta_H'])
    env_alta = hv.Area(perfil, label='Envolvente', **dims_alta)
    env_alta.opts(alpha=0.3,color='green',fontscale=1.5,title='Perfil ALTA Qoi')

    linea_alta = hv.Curve(perfil.alta_M,label='P50')
    linea_alta.opts(color='green',line_dash='dotted')

    plots_perfiles = env_baja * linea_baja + env_media * linea_media + env_alta * linea_alta


    fig2 = hv.render(plots_perfiles)

    hv.output(plots_perfiles, backend='bokeh', fig='html', size=200)

    hv.save(plots_perfiles, 'curvas_tipo.html')

    return
Ejemplo n.º 20
0
    'Asian',
    'URM',
    'White',
    'International',
    'Unknown',
]

p_bars = hv.Bars(df_bar,
                 kdims=['Year', 'variable'],
                 vdims=['frac', 'Level', 'USonly',
                        'Group']).redim.values(variable=stack_order).groupby(
                            ['Level', 'USonly', 'Group']).opts(
                                cmap=cmap,
                                labelled=[],
                                tools=['hover'],
                                stacked=True,
                                width=800,
                                height=400,
                                yaxis=None,
                                ylim=(None, None),
                                title='',
                                legend_offset=(0, 0),
                                legend_position="bottom",
                                show_legend=True,
                            )

# In[11]:

df_bar = df.apply(flip_y, axis=1)


def format_pct(x):
Ejemplo n.º 21
0
def showmissingpertrack(data, percentage=False):
    "show missing per track"
    if percentage:
        return hv.Bars(data.delta.isna().sum(level=0) /
                       data.delta.count(level=0))
    return hv.Bars(data.delta.isna().sum(level=0))
subset3["Course ID #"] = subset3["courseid_num"]

plot_opts = dict(show_legend=False,
                 color_index='Course Currently Selected',
                 title="Engagement Scores Across Your Company Courses",
                 width=600,
                 xlabel='Course ID #',
                 ylabel='Engagement Score',
                 ylim=(0, 110),
                 xrotation=45,
                 tools=['hover'])

style_opts = dict(box_color=hv.Cycle(['#30a2da', '#fc4f30']))

bars = hv.Bars(
    subset3, hv.Dimension('Course ID #'),
    ['Engagement Score', 'Course Currently Selected', 'Number of Users'])

bars = bars.opts(plot=plot_opts, style=style_opts)

st.write(hv.render(bars))

##############################################################################

#### Writing current engagement score ####

##############################################################################

subset2 = subset[subset['courseid_num'] == course_selection]
subset2.reset_index(drop=True, inplace=True)
pd.DataFrame(
    confusion_matrix(
        digits_y_sparse.numpy().argmax(axis=1), digits_y_hat.argmax(axis=1)
    ),
    index=range(1, 10),
    columns=range(1, 10),
)

#%%
lead_prob = digits_tree.leaf_probabilty(digits_X)

P = tf.concat([tf.reshape(x, (-1, 1)) for x in lead_prob], 1)

pd.np.random.choice(range(1000), 5)

hv.Bars(tf.random.shuffle(P)[1, :].numpy())


#%%
prototype_labels = []
for s, p in zip(digits_tree.leaf(digits_X), digits_tree.leaf_probabilty(digits_X)):
    prototype_labels.append(s * tf.reshape(p, (-1, 1)))

prototype_labels = list(
    map(lambda x: (tf.reduce_mean(x, 0).numpy().argmax(0)), prototype_labels)
)
prototypes = list(map(lambda x: tf.reduce_mean(x, 0), digits_tree.prototype(digits_X)))

#%%
images = []
for i, (proto, label) in enumerate(zip(prototypes, prototype_labels)):
Ejemplo n.º 24
0
def stacked_bar_plot(SBJ, WL):
    sleep_df_TR = pd.DataFrame(columns=['sleep value', 'sleep stage'])
    for RUN in ['SleepAscending', 'SleepDescending', 'SleepRSER']:
        DATA_df = load_sleep_stage_data(SBJ,
                                        RUN,
                                        WL,
                                        window=False,
                                        fill_TR=False)
        temp_df = DATA_df[['sleep value', 'sleep stage']].copy()
        sleep_df_TR = sleep_df_TR.append(temp_df).reset_index(drop=True)

    wake_df_TR = pd.DataFrame(columns=['sleep value', 'sleep stage'])
    for RUN in ['WakeAscending', 'WakeDescending', 'WakeRSER']:
        DATA_df = load_sleep_stage_data(SBJ,
                                        RUN,
                                        WL,
                                        window=False,
                                        fill_TR=False)
        temp_df = DATA_df[['sleep value', 'sleep stage']].copy()
        wake_df_TR = wake_df_TR.append(temp_df).reset_index(drop=True)

    sleep_df_WIN = pd.DataFrame(columns=['sleep value', 'sleep stage'])
    for RUN in ['SleepAscending', 'SleepDescending', 'SleepRSER']:
        DATA_df = load_sleep_stage_data(SBJ,
                                        RUN,
                                        WL,
                                        window=True,
                                        fill_TR=False)
        temp_df = DATA_df[['sleep value', 'sleep stage']].copy()
        sleep_df_WIN = sleep_df_WIN.append(temp_df).reset_index(drop=True)

    wake_df_WIN = pd.DataFrame(columns=['sleep value', 'sleep stage'])
    for RUN in ['WakeAscending', 'WakeDescending', 'WakeRSER']:
        DATA_df = load_sleep_stage_data(SBJ,
                                        RUN,
                                        WL,
                                        window=True,
                                        fill_TR=False)
        temp_df = DATA_df[['sleep value', 'sleep stage']].copy()
        wake_df_WIN = wake_df_WIN.append(temp_df).reset_index(drop=True)

    percent_df = pd.DataFrame(
        columns=['Time', 'Run', 'Sleep Stage', 'Percent'])

    sleep_list_TR = list(sleep_df_TR['sleep stage'])
    for stage in ['Wake', 'Stage 1', 'Stage 2', 'Stage 3', 'Undetermined']:
        percent_df.loc[len(percent_df.index)] = [
            'TR', 'Sleep', stage,
            (sleep_list_TR.count(stage)) / len(sleep_list_TR) * 100
        ]
    wake_list_TR = list(wake_df_TR['sleep stage'])
    for stage in ['Wake', 'Stage 1', 'Stage 2', 'Stage 3', 'Undetermined']:
        percent_df.loc[len(percent_df.index)] = [
            'TR', 'Wake', stage,
            (wake_list_TR.count(stage)) / len(wake_list_TR) * 100
        ]

    sleep_list_WIN = list(sleep_df_WIN['sleep stage'])
    for stage in ['Wake', 'Stage 1', 'Stage 2', 'Stage 3', 'Undetermined']:
        percent_df.loc[len(percent_df.index)] = [
            'Window', 'Sleep', stage,
            (sleep_list_WIN.count(stage)) / len(sleep_list_WIN) * 100
        ]
    wake_list_WIN = list(wake_df_WIN['sleep stage'])
    for stage in ['Wake', 'Stage 1', 'Stage 2', 'Stage 3', 'Undetermined']:
        percent_df.loc[len(percent_df.index)] = [
            'Window', 'Wake', stage,
            (wake_list_WIN.count(stage)) / len(wake_list_WIN) * 100
        ]

    color_key = {
        'Wake': 'orange',
        'Stage 1': 'yellow',
        'Stage 2': 'green',
        'Stage 3': 'blue',
        'Undetermined': 'gray'
    }
    output = hv.Bars(percent_df,
                     kdims=['Run', 'Sleep Stage', 'Time'],
                     group='Time').opts(cmap=color_key,
                                        xlabel=' ',
                                        ylim=(0, 100),
                                        width=800,
                                        height=350,
                                        title='Sleep Stage Bar Graph for ' +
                                        SBJ)
    return output
Ejemplo n.º 25
0
    return percent_df


all_percent_df = all_sleep_data_TR(sub_list)
color_key = {
    'Wake': 'orange',
    'Stage 1': 'yellow',
    'Stage 2': 'green',
    'Stage 3': 'blue',
    'Undetermined': 'gray'
}
hv.Bars(all_percent_df,
        kdims=['Run', 'Sleep_Stage'
               ]).opts(cmap=color_key,
                       xlabel=' ',
                       ylim=(0, 100),
                       width=800,
                       height=350,
                       title='Sleep Stage Bar Graph for All Subjects')

# ***
# ## Comparing Percent of Sleep Stages by TR vs Window
# To see if the "winner takes all" method of determining sleep stage per window we plot both bar plots on top of each other.


@pn.depends(SubjSelect.param.value, WindowSelect.param.value)
def sleep_bar_graph_WIN(SBJ, WL):
    sleep_df = pd.DataFrame(columns=['sleep value', 'sleep stage'])
    for RUN in ['SleepAscending', 'SleepDescending', 'SleepRSER']:
        DATA_df = load_sleep_stage_data(SBJ,
                                        RUN,
renderer = hv.renderer('bokeh')

df1 = df[df['size'] != 'Varies with device']

df1.loc[df1['size'].str[-1] == 'k',
        ['size']] = pd.to_numeric(df1['size'].str[:-1], errors='coerce') / 1000

df1['size'] = df1['size'].str[0:-1]
df1['size'] = pd.to_numeric(df1['size'], errors='coerce')
category_size = df1[['category', 'size']].dropna()

category_size = category_size.groupby('category', as_index=False).mean()

category_size.set_index('category', inplace=True)
v = category_size["size"].values.tolist()
i = category_size["size"].index.tolist()

bars = hv.Bars((i, v), hv.Dimension('category'),
               'size').opts(tools=['hover'],
                            xformatter=formatter,
                            show_legend=False,
                            fill_color=dim('category').str(),
                            cmap='coolwarm')  #  '#E933FF'
t = (bars.relabel('Avg. size by category').opts(invert_axes=True,
                                                height=650,
                                                width=1000))

renderer.save(t, "./Data/average_size")

# ***************************************************************************
Ejemplo n.º 27
0
 def _get_bokeh_chart(self,
                      x_field,
                      y_field,
                      chart_type,
                      label,
                      opts,
                      style,
                      options={},
                      **kwargs):
     """
     Get a Bokeh chart object
     """
     if isinstance(x_field, list):
         kdims = x_field
     else:
         kdims = [x_field]
     if isinstance(y_field, list):
         vdims = y_field
     else:
         vdims = [y_field]
     args = kwargs
     args["data"] = self.df
     args["kdims"] = kdims
     args["vdims"] = vdims
     if label is not None:
         args["label"] = label
     else:
         if self.label is not None:
             args["label"] = self.label
     chart = None
     try:
         if chart_type == "line":
             chart = hv.Curve(**args)
         if chart_type == "hline":
             chart = self._hline_bokeh_(y_field)
         elif chart_type == "point":
             chart = hv.Scatter(**args)
         elif chart_type == "area":
             chart = hv.Area(**args)
         elif chart_type == "bar":
             chart = hv.Bars(**args)
         elif chart_type == "hist":
             chart = hv.Histogram(**args)
         elif chart_type == "errorBar":
             chart = hv.ErrorBars(**args)
         elif chart_type == "heatmap":
             chart = hv.HeatMap(**args)
         elif chart_type == "lreg":
             chart = self._lreg_bokeh(**args)
         elif chart_type == "sline":
             window_size, y_label = options["window_size"],
             options["y_label"]
             chart = self._sline_bokeh(window_size, y_label)
         if chart is None:
             self.err("Chart type " + chart_type + " unknown",
                      self._get_bokeh_chart)
             return
         endchart = chart(plot=opts, style=style)
         return endchart
     except DataError as e:
         msg = "Column not found in " + x_field + " and " + y_field
         self.err(e, self._get_bokeh_chart, msg)
     except Exception as e:
         self.err(e)
Ejemplo n.º 28
0
pool = Pool()
json_data = pool.map(get_json_data, worker_keys)

sg_client.describe_workteam(WorkteamName=workTeamName)

response = cognito_client.list_users(UserPoolId=user_pool_id)

user_dict = {}
for user in response['Users']:
    for attr in user['Attributes']:
        if attr['Name'] == 'sub':
            user_dict[attr['Value']] = user

labels = []
for data in json_data:
    for a in data['answers']:
        sub = a['workerMetadata']['identityData']['sub']
        labels.append(user_dict[sub]['Username'])

renderer = hv.renderer('bokeh')

bars = hv.Bars(Counter(labels)).opts(
    width=width,
    height=height,
    title='Labeled/Unlabeled: ' + str(labeled_so_far) + '/' + str(unlabeled))

layout = bars

doc = renderer.server_doc(layout)
doc.title = 'Labeling Job Status'
        for i in open(base_dir + 'kyoto-train.en', 'r').readlines()
    ]
    df = pd.DataFrame({"ja": ja, "en": en}).iloc[0:3000, :]

    # Japanese PreProcessing
    df['ja_preprocessed'] = df['ja'].apply(lambda x: ja_preprocess(x))
    # English PreProcessing
    df['en_preprocessed'] = df['en'].apply(lambda x: en_preprocess(x))

    # English tfidf / bow features
    en_bow = bow_features(df['en_preprocessed'],
                          _max_features=10,
                          _max_ngrams=1)
    en_tfidf = tfidf_features(df['en_preprocessed'],
                              _max_features=10,
                              _max_ngrams=1)

    # English Ngram Count
    en_ngram = ngram_count(df['en_preprocessed'], ngram=1, common_num=30)
    # Ngram Count Bar Plot
    en_ngram_graph = hv.Bars(en_ngram[::-1]) \
        .opts(opts.Bars(title="Ngram Count", color="red", xlabel="Unigrams", ylabel="Count", width=400, height=600, show_grid=True, invert_axes=True))
    hv.save(en_ngram_graph, 'en_graph.html')

    # Japanese WordCloud
    wordCloud(df['ja_preprocessed'],
              _font_path='NotoSansCJKjp-Regular.otf',
              _output_file='wordCloud_ja.png')
    # English WordCloud
    wordCloud(df['en_preprocessed'], _output_file='wordCloud_en.png')
Ejemplo n.º 30
0
from bokeh.plotting import figure, output_file, show
import holoviews as hv 
hv.extension('bokeh')

# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output to static HTML file
output_file("lines.html")

data = [('one',8),('two', 10), ('three', 16), ('four', 8), ('five', 4), ('six', 1)]
bars = hv.Bars(data, hv.Dimension('Car occupants'), 'Count')


"""
# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y', toolbar_location=None)

# add a line renderer with legend and line thickness
p.line(x, y, legend="Temp.", line_width=2)
"""


# show the results
show(bars)