parula.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from matplotlib.colors import LinearSegmentedColormap
  2. def main(N: int) -> LinearSegmentedColormap:
  3. """
  4. Returns a Parula colormap to be used with matplotlib's `cycler`. `cm_data` has values copied from MATLAB for
  5. `parula(64)`.
  6. Parameters
  7. ----------
  8. N : int
  9. Number of RGB quantization levels.
  10. Returns
  11. -------
  12. LinearSegmentedColormap
  13. Parula color map.
  14. """
  15. cm_data = [
  16. [0.2422, 0.1504, 0.6603],
  17. [0.25039048, 0.16499524, 0.70761429],
  18. [0.25777143, 0.18178095, 0.7511381],
  19. [0.26472857, 0.19775714, 0.79521429],
  20. [0.27064762, 0.21467619, 0.83637143],
  21. [0.27511429, 0.2342381, 0.87098571],
  22. [0.2783, 0.25587143, 0.89907143],
  23. [0.28033333, 0.27823333, 0.9221],
  24. [0.2813381, 0.30059524, 0.94137619],
  25. [0.28101429, 0.32275714, 0.95788571],
  26. [0.27946667, 0.34467143, 0.97167619],
  27. [0.27597143, 0.36668095, 0.98290476],
  28. [0.26991429, 0.3892, 0.9906],
  29. [0.26024286, 0.41232857, 0.99515714],
  30. [0.24403333, 0.43583333, 0.99883333],
  31. [0.22064286, 0.46025714, 0.99728571],
  32. [0.19633333, 0.48471905, 0.98915238],
  33. [0.18340476, 0.50737143, 0.97979524],
  34. [0.17864286, 0.52885714, 0.96815714],
  35. [0.1764381, 0.54990476, 0.95201905],
  36. [0.16874286, 0.5702619, 0.93587143],
  37. [0.154, 0.5902, 0.9218],
  38. [0.14602857, 0.60911905, 0.90785714],
  39. [0.13802381, 0.62762857, 0.89729048],
  40. [0.12481429, 0.64592857, 0.88834286],
  41. [0.11125238, 0.6635, 0.87631429],
  42. [0.09520952, 0.67982857, 0.85978095],
  43. [0.06887143, 0.69477143, 0.83935714],
  44. [0.02966667, 0.70816667, 0.81633333],
  45. [0.00357143, 0.72026667, 0.7917],
  46. [0.00665714, 0.73121429, 0.76601429],
  47. [0.04332857, 0.74109524, 0.73940952],
  48. [0.09639524, 0.75, 0.7120381],
  49. [0.14077143, 0.7584, 0.68415714],
  50. [0.1717, 0.7669619, 0.65544286],
  51. [0.19376667, 0.77576667, 0.6251],
  52. [0.21608571, 0.7843, 0.5923],
  53. [0.24695714, 0.79179524, 0.55674286],
  54. [0.29061429, 0.79729048, 0.51882857],
  55. [0.34064286, 0.8008, 0.47885714],
  56. [0.3909, 0.80287143, 0.43544762],
  57. [0.44562857, 0.80241905, 0.39091905],
  58. [0.5044, 0.7993, 0.348],
  59. [0.5615619, 0.79423333, 0.30448095],
  60. [0.61739524, 0.78761905, 0.2612381],
  61. [0.67198571, 0.77927143, 0.2227],
  62. [0.7242, 0.76984286, 0.19102857],
  63. [0.77383333, 0.75980476, 0.16460952],
  64. [0.82031429, 0.74981429, 0.15352857],
  65. [0.86343333, 0.7406, 0.15963333],
  66. [0.90354286, 0.73302857, 0.17741429],
  67. [0.93925714, 0.72878571, 0.20995714],
  68. [0.97275714, 0.72977143, 0.23944286],
  69. [0.99564762, 0.74337143, 0.23714762],
  70. [0.99698571, 0.76585714, 0.21994286],
  71. [0.99520476, 0.78925238, 0.2027619],
  72. [0.9892, 0.81356667, 0.18853333],
  73. [0.97862857, 0.83862857, 0.17655714],
  74. [0.96764762, 0.8639, 0.16429048],
  75. [0.96100952, 0.88901905, 0.15367619],
  76. [0.95967143, 0.91345714, 0.14225714],
  77. [0.96279524, 0.9373381, 0.12650952],
  78. [0.96911429, 0.96062857, 0.1063619],
  79. [0.9769, 0.9839, 0.0805],
  80. ]
  81. return LinearSegmentedColormap.from_list(name="parula", colors=cm_data, N=N)