本文整理匯總了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
示例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
示例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
示例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
示例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'}))
示例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)