Python matplotlib.colors.cnames() Examples
The following are 20
code examples of matplotlib.colors.cnames().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.colors
, or try the search function
.
Example #1
Source File: common.py From typhon with MIT License | 6 votes |
def _to_hex(c): """Convert arbitray color specification to hex string.""" ctype = type(c) # Convert rgb to hex. if ctype is tuple or ctype is np.ndarray or ctype is list: return colors.rgb2hex(c) if ctype is str: # If color is already hex, simply return it. regex = re.compile('^#[A-Fa-f0-9]{6}$') if regex.match(c): return c # Convert named color to hex. return colors.cnames[c] raise Exception("Can't handle color of type: {}".format(ctype))
Example #2
Source File: plot.py From VerticaPy with Apache License 2.0 | 6 votes |
def gen_colors(): colors = ['#263133', '#FE5016', '#0073E7', '#19A26B', '#FCDB1F', '#000000', '#2A6A74', '#861889', '#00B4E0', '#90EE90', '#FF7F50', '#B03A89'] all_colors = [item for item in plt_colors.cnames] shuffle(all_colors) for c in all_colors: if c not in colors: colors += [c] return colors #---#
Example #3
Source File: colors.py From flavio with MIT License | 6 votes |
def darken_color(color, amount=0.5): """ Darkens the given color by multiplying luminosity by the given amount. Input can be matplotlib color string, hex string, or RGB tuple. Examples: >> lighten_color('g', 0.3) >> lighten_color('#F034A3', 0.6) >> lighten_color((.3,.55,.1), 0.5) """ import matplotlib.colors as mc import colorsys try: c = mc.cnames[color] except: c = color c = colorsys.rgb_to_hls(*mc.to_rgb(c)) return colorsys.hls_to_rgb(c[0], amount * c[1], c[2])
Example #4
Source File: colors.py From flavio with MIT License | 6 votes |
def lighten_color(color, amount=0.5): """ Lightens the given color by multiplying (1-luminosity) by the given amount. Input can be matplotlib color string, hex string, or RGB tuple. Examples: >> lighten_color('g', 0.3) >> lighten_color('#F034A3', 0.6) >> lighten_color((.3,.55,.1), 0.5) """ import matplotlib.colors as mc import colorsys try: c = mc.cnames[color] except: c = color c = colorsys.rgb_to_hls(*mc.to_rgb(c)) return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2])
Example #5
Source File: test_series.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #6
Source File: test_series.py From recruit with Apache License 2.0 | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #7
Source File: test_series.py From coffeegrindsize with MIT License | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #8
Source File: colors.py From vectorbt with GNU General Public License v3.0 | 5 votes |
def adjust_lightness(color, amount=0.7): """Lightens the given color by multiplying (1-luminosity) by the given amount. Input can be matplotlib color string, hex string, or RGB tuple. Output will be an RGB string.""" import matplotlib.colors as mc import colorsys try: c = mc.cnames[color] except: c = color c = colorsys.rgb_to_hls(*mc.to_rgb(c)) rgb = colorsys.hls_to_rgb(c[0], max(0, min(1, amount * c[1])), c[2]) return 'rgb(%d,%d,%d)' % (int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))
Example #9
Source File: test_series.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #10
Source File: util.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def is_color(color): """ Checks if supplied object is a valid color spec. """ if not isinstance(color, basestring): return False elif RGB_HEX_REGEX.match(color): return True elif color in COLOR_ALIASES: return True elif color in cnames: return True return False
Example #11
Source File: colors.py From iterativeWGCNA with GNU General Public License v2.0 | 5 votes |
def assign_color(self, n): ''' assigns a color if n <= len(base_colors) assigns the base color whose index is n - 1 else generates a random color ''' color = None if n <= len(self.base_colors): color = ref_colors.cnames[self.base_colors[n - 1]] # get hex representation else: color = self.__generate_random_color() self.used_colors.append(color) return color
Example #12
Source File: Util.py From Predicting-Health-Insurance-Cost with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getColorNames(): colorNames = [] for color in colors.cnames: colorNames.append(color) return colorNames
Example #13
Source File: DataAnalysis.py From Predicting-Health-Insurance-Cost with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getColorNames(): colorNames = [] for color in colors.cnames: colorNames.append(color) return colorNames
Example #14
Source File: utils.py From scvelo with BSD 3-Clause "New" or "Revised" License | 5 votes |
def rgb_custom_colormap(colors=None, alpha=None, N=256): """Creates a custom colormap. Colors can be given as names or rgb values. Arguments --------- colors: : `list` or `array` (default `['royalblue', 'white', 'forestgreen']`) List of colors, either as names or rgb values. alpha: `list`, `np.ndarray` or `None` (default: `None`) Alpha of the colors. Must be same length as colors. N: `int` (default: `256`) y coordinate Returns ------- A ListedColormap """ if colors is None: colors = ["royalblue", "white", "forestgreen"] c = [] if "transparent" in colors: if alpha is None: alpha = [1 if i != "transparent" else 0 for i in colors] colors = [i if i != "transparent" else "white" for i in colors] for color in colors: if isinstance(color, str): color = to_rgb(color if color.startswith("#") else cnames[color]) c.append(color) if alpha is None: alpha = np.ones(len(c)) vals = np.ones((N, 4)) ints = len(c) - 1 n = int(N / ints) for j in range(ints): for i in range(3): vals[n * j : n * (j + 1), i] = np.linspace(c[j][i], c[j + 1][i], n) vals[n * j : n * (j + 1), -1] = np.linspace(alpha[j], alpha[j + 1], n) return ListedColormap(vals)
Example #15
Source File: test_series.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #16
Source File: analyser.py From spotpy with MIT License | 5 votes |
def plot_objectivefunctiontraces(results,evaluation,algorithms,fig_name='Like_trace.png'): import matplotlib.pyplot as plt from matplotlib import colors cnames=list(colors.cnames) font = {'family' : 'calibri', 'weight' : 'normal', 'size' : 20} plt.rc('font', **font) fig=plt.figure(figsize=(16,3)) xticks=[5000,15000] for i in range(len(results)): ax = plt.subplot(1,len(results),i+1) likes=calc_like(results[i],evaluation,spotpy.objectivefunctions.rmse) ax.plot(likes,'b-') ax.set_ylim(0,25) ax.set_xlim(0,len(results[0])) ax.set_xlabel(algorithms[i]) ax.xaxis.set_ticks(xticks) if i==0: ax.set_ylabel('RMSE') ax.yaxis.set_ticks([0,10,20]) else: ax.yaxis.set_ticks([]) plt.tight_layout() fig.savefig(fig_name)
Example #17
Source File: test_series.py From vnpy_crypto with MIT License | 5 votes |
def test_standard_colors_all(self): import matplotlib.colors as colors from pandas.plotting._style import _get_standard_colors # multiple colors like mediumaquamarine for c in colors.cnames: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3 # single letter colors like k for c in colors.ColorConverter.colors: result = _get_standard_colors(num_colors=1, color=c) assert result == [c] result = _get_standard_colors(num_colors=1, color=[c]) assert result == [c] result = _get_standard_colors(num_colors=3, color=c) assert result == [c] * 3 result = _get_standard_colors(num_colors=3, color=[c]) assert result == [c] * 3
Example #18
Source File: plotutil.py From PlotIt with MIT License | 4 votes |
def plot_dot(xyval, color_name, xlabel, ylabel, theme, gui, dot_style, file_path): # Show plot summary print('***** Plot Summary *****') print('X,Y Value: {}'.format(xyval)) print('Color: {}'.format(color_name)) print('X-label: {}'.format(xlabel)) print('Y-label: {}'.format(ylabel)) if theme == 'dark': mplstyle.use('dark_background') else: mplstyle.use('default') try: # Check if color is hex code is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name) if not is_hex: colors = mcolors.cnames if color_name not in colors: print(color_name, ": Color not found.") color_name = 'blue' xy=xyval.split(',') l=len(xy) #Check if even number of arguments are given if (l%2==0): #Extract x-values from xyval string xval=[float(xy[i]) for i in range(0,l,2)] #Extract y-values from xyval string yval=[float(xy[i]) for i in range(1,l+1,2)] plt.scatter(xval, yval, color=color_name, marker=dot_style) plt.savefig(file_path) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(r'$ ' + xyval + ' $') if file_path != "": plt.savefig(file_path) plt.grid(True) if not gui: plt.show() else: if not os.path.exists('.temp/'): os.mkdir('.temp/') plt.savefig(".temp/generated_plot.png") else: print("Cannot plot odd Number of Coordinates") except Exception as e: print("An error occured.",e) plt.cla() plt.clf()
Example #19
Source File: plotutil.py From PlotIt with MIT License | 4 votes |
def plot_line(arrays, color_name, xlabel, ylabel, theme, gui, line_style, file_path): # Show plot summary print('***** Plot Summary *****') print('Arrays: {}'.format(arrays)) print('Color: {}'.format(color_name)) print('X-label: {}'.format(xlabel)) print('Y-label: {}'.format(ylabel)) if theme == 'dark': mplstyle.use('dark_background') else: mplstyle.use('default') try: # Check if color is hex code is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name) if not is_hex: colors = mcolors.cnames if color_name not in colors: print(color_name, ": Color not found.") color_name = 'blue' # Extract numbers from X-array xvals = list(map(float, arrays[1:arrays.find(']')].split(','))) # Extract numbers from Y-array yvals = list(map(float, arrays[arrays.find(']') + 3:len(arrays) - 1].split(','))) if len(xvals) == len(yvals): plt.plot(xvals, yvals, color=color_name, linewidth=2.0, linestyle=line_style) plt.savefig(file_path) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(r'$ ' + 'Line:' + str(xvals) +','+ str(yvals) + ' $') if file_path != "": plt.savefig(file_path) else: print("Error: You need same number of X and Y values") except Exception: raise InvalidFunctionException('Values are improper') if file_path != "": plt.savefig(file_path) plt.grid(True) if not gui: plt.show() else: if not os.path.exists('.temp/'): os.mkdir('.temp/') plt.savefig(".temp/generated_plot.png") plt.cla() plt.clf()
Example #20
Source File: plotutil.py From PlotIt with MIT License | 4 votes |
def plot(func, xpoints, color_name, xlabel, ylabel, theme, gui, line_style, file_path, discrete=False): # Show plot summary print('***** Plot Summary *****') print("Funtion: {}".format(func)) if discrete: print("Plotting funcion for points: {}".format(', '.join(map(str, xpoints)))) else: print("Starting abcissa: {}".format(xpoints[0])) print("Ending abcissa: {}".format(xpoints[-1])) if (len(xpoints) > 1): print("Stepsize: {}".format(xpoints[1] - xpoints[0])) print("Color: {}".format(color_name)) print("X-label: {}".format(xlabel)) print("Y-label: {}".format(ylabel)) print() if theme == 'dark': mplstyle.use('dark_background') else: mplstyle.use('default') xvals = xpoints yvals = create_y_values(func, xvals) try: # Check if color is hex code is_hex = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color_name) if not is_hex: colors = mcolors.cnames if color_name not in colors: print(color_name, ": Color not found.") color_name = 'blue' plt.plot(xvals, yvals, color=color_name, linewidth=2.0, linestyle=line_style) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.title(r'$ ' + func + ' $') except Exception: print("An error occured.") if file_path != "": plt.savefig(file_path) plt.grid(True) if not gui: plt.show() else: if not os.path.exists('.temp/'): os.mkdir('.temp/') plt.savefig(".temp/generated_plot.png") plt.cla() plt.clf()