Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

cbrewer.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. function [colormap]=cbrewer(ctype, cname, ncol, interp_method)
  2. %
  3. % CBREWER - This function produces a colorbrewer table (rgb data) for a
  4. % given type, name and number of colors of the colorbrewer tables.
  5. % For more information on 'colorbrewer', please visit
  6. % http://colorbrewer2.org/
  7. %
  8. % The tables were generated from an MS-Excel file provided on the website
  9. % http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html
  10. %
  11. % INPUT:
  12. % - ctype: type of color table 'seq' (sequential), 'div' (diverging), 'qual' (qualitative)
  13. % - cname: name of colortable. It changes depending on ctype.
  14. % - ncol: number of color in the table. It changes according to ctype and
  15. % cname
  16. % - interp_method: if the table need to be interpolated, what method
  17. % should be used for interp1? Default='cubic'.
  18. %
  19. % A note on the number of colors: Based on the original data, there is
  20. % only a certain number of colors available for each type and name of
  21. % colortable. When 'ncol' is larger then the maximum number of colors
  22. % originally given, an interpolation routine is called (interp1) to produce
  23. % the "extended" colormaps.
  24. %
  25. % Example: To produce a colortable CT of ncol X 3 entries (RGB) of
  26. % sequential type and named 'Blues' with 8 colors:
  27. % CT=cbrewer('seq', 'Blues', 8);
  28. % To use this colortable as colormap, simply call:
  29. % colormap(CT)
  30. %
  31. % To see the various colormaps available according to their types and
  32. % names, simply call: cbrewer()
  33. %
  34. % This product includes color specifications and designs developed by
  35. % Cynthia Brewer (http://colorbrewer.org/).
  36. %
  37. % Author: Charles Robert
  38. % email: tannoudji@hotmail.com
  39. % Date: 06.12.2011
  40. % load colorbrewer data
  41. load('colorbrewer.mat')
  42. % initialise the colormap is there are any problems
  43. colormap=[];
  44. if (~exist('interp_method', 'var'))
  45. interp_method='cubic';
  46. end
  47. % If no arguments
  48. if (~exist('ctype', 'var') | ~exist('cname', 'var') | ~exist('ncol', 'var'))
  49. disp(' ')
  50. disp('INPUT:')
  51. disp(' - ctype: type of color table *seq* (sequential), *div* (divergent), *qual* (qualitative)')
  52. disp(' - cname: name of colortable. It changes depending on ctype.')
  53. disp(' - ncol: number of color in the table. It changes according to ctype and cname')
  54. disp(' ')
  55. disp('Sequential tables:')
  56. z={'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd',...
  57. 'Purples','RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd'};
  58. z(:)
  59. disp('Divergent tables:')
  60. z={'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn'};
  61. z(:)
  62. disp(' ')
  63. disp('Qualitative tables:')
  64. %getfield(colorbrewer, 'qual')
  65. z={'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3'};
  66. z(:)
  67. plot_brewer_cmap
  68. return
  69. end
  70. % Verify that the input is appropriate
  71. ctype_names={'div', 'seq', 'qual'};
  72. if (~ismember(ctype,ctype_names))
  73. disp('ctype must be either: *div*, *seq* or *qual*')
  74. colormap=[];
  75. return
  76. end
  77. if (~isfield(colorbrewer.(ctype),cname))
  78. disp(['The name of the colortable of type *' ctype '* must be one of the following:'])
  79. getfield(colorbrewer, ctype)
  80. colormap=[];
  81. return
  82. end
  83. if (ncol>length(colorbrewer.(ctype).(cname)))
  84. % disp(' ')
  85. % disp('----------------------------------------------------------------------')
  86. % disp(['The maximum number of colors for table *' cname '* is ' num2str(length(colorbrewer.(ctype).(cname)))])
  87. % disp(['The new colormap will be extrapolated from these ' num2str(length(colorbrewer.(ctype).(cname))) ' values'])
  88. % disp('----------------------------------------------------------------------')
  89. % disp(' ')
  90. cbrew_init=colorbrewer.(ctype).(cname){length(colorbrewer.(ctype).(cname))};
  91. colormap=interpolate_cbrewer(cbrew_init, interp_method, ncol);
  92. colormap=colormap./255;
  93. return
  94. end
  95. if (isempty(colorbrewer.(ctype).(cname){ncol}))
  96. while(isempty(colorbrewer.(ctype).(cname){ncol}))
  97. ncol=ncol+1;
  98. end
  99. disp(' ')
  100. disp('----------------------------------------------------------------------')
  101. disp(['The minimum number of colors for table *' cname '* is ' num2str(ncol)])
  102. disp('This minimum value shall be defined as ncol instead')
  103. disp('----------------------------------------------------------------------')
  104. disp(' ')
  105. end
  106. colormap=(colorbrewer.(ctype).(cname){ncol})./255;
  107. end