Guest User

Untitled

a guest
Jun 24th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. def make_colormap(seq):
  2. """Return a LinearSegmentedColormap
  3. seq: a sequence of floats and RGB-tuples. The floats should be increasing
  4. and in the interval (0,1).
  5. """
  6. seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
  7. cdict = {'red': [], 'green': [], 'blue': []}
  8. for i, item in enumerate(seq):
  9. if isinstance(item, float):
  10. r1, g1, b1 = seq[i - 1]
  11. r2, g2, b2 = seq[i + 1]
  12. cdict['red'].append([item, r1, r2])
  13. cdict['green'].append([item, g1, g2])
  14. cdict['blue'].append([item, b1, b2])
  15.  
  16. return mcolors.LinearSegmentedColormap('CustomMap', cdict)
  17.  
  18. #main#
  19. c = mcolors.ColorConverter().to_rgb
  20. rvb = make_colormap(
  21. [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')])
  22.  
  23. N = 1000
  24. array_dg = np.random.uniform(0, 10, size=(N, 2))
  25. colors = np.random.uniform(0, 5, size=(N,))
  26. plt.scatter(array_dg[:, 0], array_dg[:, 1], c=colors, cmap=rvb)
  27. plt.colorbar()
  28. plt.show()
  29.  
  30. import matplotlib.pyplot as plt
  31. import matplotlib.colors as mcolors
  32. import numpy as np
  33.  
  34. def make_colormap(seq):
  35. """Return a LinearSegmentedColormap
  36. seq: a sequence of floats and RGB-tuples. The floats should be increasing
  37. and in the interval (0,1).
  38. """
  39. seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
  40. cdict = {'red': [], 'green': [], 'blue': []}
  41. for i, item in enumerate(seq):
  42. if isinstance(item, float):
  43. r1, g1, b1 = seq[i - 1]
  44. r2, g2, b2 = seq[i + 1]
  45. cdict['red'].append([item, r1, r2])
  46. cdict['green'].append([item, g1, g2])
  47. cdict['blue'].append([item, b1, b2])
  48.  
  49. return mcolors.LinearSegmentedColormap('CustomMap', cdict)
  50.  
  51.  
  52. c = mcolors.ColorConverter().to_rgb
  53. rvb = make_colormap(
  54. [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')])
  55.  
  56. N = 60
  57. x = np.arange(N).astype(float)
  58. y = np.random.uniform(0, 5, size=(N,))
  59.  
  60. plt.bar(x,y, color=rvb(x/N))
  61. plt.show()
  62.  
  63. ax = sns.barplot("size", y="total_bill", data=tips, palette="Blues_d")
Add Comment
Please, Sign In to add comment