当前位置: 首页>>代码示例>>Python>>正文


Python colorlover.scales方法代码示例

本文整理汇总了Python中colorlover.scales方法的典型用法代码示例。如果您正苦于以下问题:Python colorlover.scales方法的具体用法?Python colorlover.scales怎么用?Python colorlover.scales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colorlover的用法示例。


在下文中一共展示了colorlover.scales方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_experiment

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def plot_experiment(experiment_spec, experiment_df, metrics_cols):
    '''
    Plot the metrics vs. specs parameters of an experiment, where each point is a trial.
    ref colors: https://plot.ly/python/heatmaps-contours-and-2dhistograms-tutorial/#plotlys-predefined-color-scales
    '''
    y_cols = metrics_cols
    x_cols = ps.difference(experiment_df.columns.tolist(), y_cols)
    fig = tools.make_subplots(rows=len(y_cols), cols=len(x_cols), shared_xaxes=True, shared_yaxes=True, print_grid=False)
    strength_sr = experiment_df['strength']
    min_strength = strength_sr.values.min()
    max_strength = strength_sr.values.max()
    for row_idx, y in enumerate(y_cols):
        for col_idx, x in enumerate(x_cols):
            x_sr = experiment_df[x]
            guard_cat_x = x_sr.astype(str) if x_sr.dtype == 'object' else x_sr
            trace = go.Scatter(
                y=experiment_df[y], yaxis=f'y{row_idx+1}',
                x=guard_cat_x, xaxis=f'x{col_idx+1}',
                showlegend=False, mode='markers',
                marker={
                    'symbol': 'circle-open-dot', 'color': experiment_df['strength'], 'opacity': 0.5,
                    # dump first quarter of colorscale that is too bright
                    'cmin': min_strength - 0.50 * (max_strength - min_strength), 'cmax': max_strength,
                    'colorscale': 'YlGnBu', 'reversescale': True
                },
            )
            fig.add_trace(trace, row_idx + 1, col_idx + 1)
            fig.layout[f'xaxis{col_idx+1}'].update(title='<br>'.join(ps.chunk(x, 20)), zerolinewidth=1, categoryarray=sorted(guard_cat_x.unique()))
        fig.layout[f'yaxis{row_idx+1}'].update(title=y, rangemode='tozero')
    fig.layout.update(
        title=f'experiment graph: {experiment_spec["name"]}',
        width=100 + 300 * len(x_cols), height=200 + 300 * len(y_cols))
    plot(fig)
    graph_prepath = experiment_spec['meta']['graph_prepath']
    save_image(fig, f'{graph_prepath}_experiment_graph.png')
    # save important graphs in prepath directly
    prepath = experiment_spec['meta']['prepath']
    save_image(fig, f'{prepath}_experiment_graph.png')
    return fig 
开发者ID:ConvLab,项目名称:ConvLab,代码行数:41,代码来源:viz.py

示例2: get_palette

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def get_palette(size):
    '''Get the suitable palette of a certain size'''
    if size <= 8:
        palette = cl.scales[str(max(3, size))]['qual']['Set2']
    else:
        palette = cl.interp(cl.scales['8']['qual']['Set2'], size)
    return palette 
开发者ID:ConvLab,项目名称:ConvLab,代码行数:9,代码来源:viz.py

示例3: get_plot_colors

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def get_plot_colors(max_colors, color_format="pyplot"):
    """Generate colors for plotting."""
    colors = cl.scales["11"]["qual"]["Paired"]
    if max_colors > len(colors):
        colors = cl.to_rgb(cl.interp(colors, max_colors))
    if color_format == "pyplot":
        return [[j / 255.0 for j in c] for c in cl.to_numeric(colors)]
    return colors 
开发者ID:facebookresearch,项目名称:pycls,代码行数:10,代码来源:plotting.py

示例4: plot_experiment

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def plot_experiment(experiment_spec, experiment_df, metrics_cols):
    '''
    Plot the metrics vs. specs parameters of an experiment, where each point is a trial.
    ref colors: https://plot.ly/python/heatmaps-contours-and-2dhistograms-tutorial/#plotlys-predefined-color-scales
    '''
    y_cols = metrics_cols
    x_cols = ps.difference(experiment_df.columns.tolist(), y_cols + ['trial'])
    fig = subplots.make_subplots(rows=len(y_cols), cols=len(x_cols), shared_xaxes=True, shared_yaxes=True, print_grid=False)
    strength_sr = experiment_df['strength']
    min_strength, max_strength = strength_sr.min(), strength_sr.max()
    for row_idx, y in enumerate(y_cols):
        for col_idx, x in enumerate(x_cols):
            x_sr = experiment_df[x]
            guard_cat_x = x_sr.astype(str) if x_sr.dtype == 'object' else x_sr
            trace = go.Scatter(
                y=experiment_df[y], yaxis=f'y{row_idx+1}',
                x=guard_cat_x, xaxis=f'x{col_idx+1}',
                showlegend=False, mode='markers',
                marker={
                    'symbol': 'circle-open-dot', 'color': strength_sr, 'opacity': 0.5,
                    # dump first portion of colorscale that is too bright
                    'cmin': min_strength - 0.5 * (max_strength - min_strength), 'cmax': max_strength,
                    'colorscale': 'YlGnBu', 'reversescale': False
                },
            )
            fig.add_trace(trace, row_idx + 1, col_idx + 1)
            fig.update_xaxes(title_text='<br>'.join(ps.chunk(x, 20)), zerolinewidth=1, categoryarray=sorted(guard_cat_x.unique()), row=len(y_cols), col=col_idx+1)
        fig.update_yaxes(title_text=y, rangemode='tozero', row=row_idx+1, col=1)
    fig.layout.update(
        title=f'experiment graph: {experiment_spec["name"]}',
        width=100 + 300 * len(x_cols), height=200 + 300 * len(y_cols))
    plot(fig)
    graph_prepath = experiment_spec['meta']['graph_prepath']
    save_image(fig, f'{graph_prepath}_experiment_graph.png')
    # save important graphs in prepath directly
    prepath = experiment_spec['meta']['prepath']
    save_image(fig, f'{prepath}_experiment_graph.png')
    return fig 
开发者ID:kengz,项目名称:SLM-Lab,代码行数:40,代码来源:viz.py

示例5: discrete_background_color_bins

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def discrete_background_color_bins(df, n_bins=5, columns='all'):
    import colorlover
    bounds = [i * (1.0 / n_bins) for i in range(n_bins + 1)]
    if columns == 'all':
        if 'id' in df:
            df_numeric_columns = df.select_dtypes('number').drop(['id'], axis=1)
        else:
            df_numeric_columns = df.select_dtypes('number')
    else:
        df_numeric_columns = df[columns]
    df_max = df_numeric_columns.max().max()
    df_min = df_numeric_columns.min().min()
    ranges = [
        ((df_max - df_min) * i) + df_min
        for i in bounds
    ]
    styles = []
    legend = []
    for i in range(1, len(bounds)):
        min_bound = ranges[i - 1]
        max_bound = ranges[i]
        backgroundColor = colorlover.scales[str(n_bins)]['seq']['Blues'][i - 1]
        color = 'white' if i > len(bounds) / 2. else 'inherit'

        for column in df_numeric_columns:
            styles.append({
                'if': {
                    'filter_query': (
                        '{{{column}}} >= {min_bound}' +
                        (' && {{{column}}} < {max_bound}' if (i < len(bounds) - 1) else '')
                    ).format(column=column, min_bound=min_bound, max_bound=max_bound),
                    'column_id': column
                },
                'backgroundColor': backgroundColor,
                'color': color
            })
        legend.append(
            html.Div(style={'display': 'inline-block', 'width': '60px'}, children=[
                html.Div(
                    style={
                        'backgroundColor': backgroundColor,
                        'borderLeft': '1px rgb(50, 50, 50) solid',
                        'height': '10px'
                    }
                ),
                html.Small(round(min_bound, 2), style={'paddingLeft': '2px'})
            ])
        )

    return (styles, html.Div(legend, style={'padding': '5px 0 5px 0'})) 
开发者ID:plotly,项目名称:dash-docs,代码行数:52,代码来源:heatmap_recipe.py

示例6: set_fontcolor

# 需要导入模块: import colorlover [as 别名]
# 或者: from colorlover import scales [as 别名]
def set_fontcolor(self, by='label', colorscale='Set3', 
                      custom_colors=None):
        """
        This function can be used to pick a metric which decides the font color
        for each extracted keyword. By default, the font color is assigned 
        based on the score of each keyword.
        
        Fonts can be picked by: 'label', 'random', 'scores', 'pos_tag', 'clustering_criteria'
        
        You can also choose custom font colors by passing in a list of 
        (R,G,B) tuples with values for each component falling in [0,255].
        
        Parameters
        ----------
        
        by : str or None, optional
            The metric used to assign font sizes. Can be None if custom colors 
            are being used
        colorscale: str or None, optional
            One of [Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues].
            When by=='scores', this will be used to determine the colorscale.
        custom_colors : list of 3-tuple, optional
            A list of RGB tuples. Each tuple corresponding to the color of
            a keyword.
            
        Returns
        -------
        None
        """
        
        if by=='label' and (custom_colors is None):
            scales = cl.scales['8']['qual']
            #All colorscales in 'scales.keys()' can be used
            
            assert colorscale in ['Pastel2','Paired','Pastel1',
                                  'Set1','Set2','Set3','Dark2','Accent']
            colors = scales[colorscale].copy()
            colors.reverse()
            
            color_mapping={key:colors[i] for i,key in enumerate(self.text_dict)}
            fontcolors =  list(map(color_mapping.get, self.labels))
            
            Wordmesh.set_fontcolor(self, custom_colors=fontcolors)
            
        else:
            #change default colorscale to a quantitative one
            colorscale = 'YlGnBu' if (colorscale=='Set3') else colorscale
            Wordmesh.set_fontcolor(self, by=by, colorscale=colorscale,
                                   custom_colors=custom_colors) 
开发者ID:mukund109,项目名称:word-mesh,代码行数:51,代码来源:static_wordmesh.py


注:本文中的colorlover.scales方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。