Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_colormap(seq):
- """Return a LinearSegmentedColormap
- seq: a sequence of floats and RGB-tuples. The floats should be increasing
- and in the interval (0,1).
- """
- seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
- cdict = {'red': [], 'green': [], 'blue': []}
- for i, item in enumerate(seq):
- if isinstance(item, float):
- r1, g1, b1 = seq[i - 1]
- r2, g2, b2 = seq[i + 1]
- cdict['red'].append([item, r1, r2])
- cdict['green'].append([item, g1, g2])
- cdict['blue'].append([item, b1, b2])
- return mcolors.LinearSegmentedColormap('CustomMap', cdict)
- #main#
- c = mcolors.ColorConverter().to_rgb
- rvb = make_colormap(
- [c('red'), 0.125, c('red'), c('orange'), 0.25, c('orange'),c('green'),0.5, c('green'),0.7, c('green'), c('blue'), 0.75, c('blue')])
- N = 1000
- array_dg = np.random.uniform(0, 10, size=(N, 2))
- colors = np.random.uniform(0, 5, size=(N,))
- plt.scatter(array_dg[:, 0], array_dg[:, 1], c=colors, cmap=rvb)
- plt.colorbar()
- plt.show()
- import matplotlib.pyplot as plt
- import matplotlib.colors as mcolors
- import numpy as np
- def make_colormap(seq):
- """Return a LinearSegmentedColormap
- seq: a sequence of floats and RGB-tuples. The floats should be increasing
- and in the interval (0,1).
- """
- seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
- cdict = {'red': [], 'green': [], 'blue': []}
- for i, item in enumerate(seq):
- if isinstance(item, float):
- r1, g1, b1 = seq[i - 1]
- r2, g2, b2 = seq[i + 1]
- cdict['red'].append([item, r1, r2])
- cdict['green'].append([item, g1, g2])
- cdict['blue'].append([item, b1, b2])
- return mcolors.LinearSegmentedColormap('CustomMap', cdict)
- c = mcolors.ColorConverter().to_rgb
- rvb = make_colormap(
- [c('red'), 0.125, c('red'), c('orange'), 0.25, c('orange'),c('green'),0.5, c('green'),0.7, c('green'), c('blue'), 0.75, c('blue')])
- N = 60
- x = np.arange(N).astype(float)
- y = np.random.uniform(0, 5, size=(N,))
- plt.bar(x,y, color=rvb(x/N))
- plt.show()
- ax = sns.barplot("size", y="total_bill", data=tips, palette="Blues_d")
Add Comment
Please, Sign In to add comment