Skip to content

Commit 54267a7

Browse files
committed
added diverging and qualitative color scales
1 parent 3ba39ae commit 54267a7

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

folium/utilities.py

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ def color_brewer(color_code, n=6):
9292
Live examples can be seen at http://colorbrewer2.org/'''
9393
maximum_n = 253
9494

95+
scheme_info = {'BuGn': 'Sequential',
96+
'BuPu': 'Sequential',
97+
'GnBu': 'Sequential',
98+
'OrRd': 'Sequential',
99+
'PuBu': 'Sequential',
100+
'PuBuGn': 'Sequential',
101+
'PuRd': 'Sequential',
102+
'RdPu': 'Sequential',
103+
'YlGn': 'Sequential',
104+
'YlGnBu': 'Sequential',
105+
'YlOrBr': 'Sequential',
106+
'YlOrRd': 'Sequential',
107+
'BrBg': 'Diverging',
108+
'PiYG': 'Diverging',
109+
'PRGn': 'Diverging',
110+
'PuOr': 'Diverging',
111+
'RdBu': 'Diverging',
112+
'RdGy': 'Diverging',
113+
'RdYlBu': 'Diverging',
114+
'RdYlGn': 'Diverging',
115+
'Spectral': 'Diverging',
116+
'Accent': 'Qualitative',
117+
'Dark2': 'Qualitative',
118+
'Paired': 'Qualitative',
119+
'Pastel1': 'Qualitative',
120+
'Pastel2': 'Qualitative',
121+
'Set1': 'Qualitative',
122+
'Set2': 'Qualitative',
123+
'Set3': 'Qualitative',
124+
}
125+
95126
schemes = {'BuGn': ['#EDF8FB', '#CCECE6', '#CCECE6', '#66C2A4', '#41AE76',
96127
'#238B45', '#005824'],
97128
'BuPu': ['#EDF8FB', '#BFD3E6', '#9EBCDA', '#8C96C6', '#8C6BB1',
@@ -115,7 +146,25 @@ def color_brewer(color_code, n=6):
115146
'YlOrBr': ['#FFFFD4', '#FEE391', '#FEC44F', '#FE9929', '#EC7014',
116147
'#CC4C02', '#8C2D04'],
117148
'YlOrRd': ['#FFFFB2', '#FED976', '#FEB24C', '#FD8D3C', '#FC4E2A',
118-
'#E31A1C', '#B10026']}
149+
'#E31A1C', '#B10026'],
150+
'BrBg': ['#8c510a', '#d8b365', '#f6e8c3', '#c7eae5', '#5ab4ac', '#01665e'],
151+
'PiYG': ['#c51b7d', '#e9a3c9', '#fde0ef', '#e6f5d0', '#a1d76a', '#4d9221'],
152+
'PRGn': ['#762a83', '#af8dc3', '#e7d4e8', '#d9f0d3', '#7fbf7b', '#1b7837'],
153+
'PuOr': ['#b35806', '#f1a340', '#fee0b6', '#d8daeb', '#998ec3', '#542788'],
154+
'RdBu': ['#b2182b', '#ef8a62', '#fddbc7', '#d1e5f0', '#67a9cf', '#2166ac'],
155+
'RdGy': ['#b2182b', '#ef8a62', '#fddbc7', '#e0e0e0', '#999999', '#4d4d4d'],
156+
'RdYlBu': ['#d73027', '#fc8d59', '#fee090', '#e0f3f8', '#91bfdb', '#4575b4'],
157+
'RdYlGn': ['#d73027', '#fc8d59', '#fee08b', '#d9ef8b', '#91cf60', '#1a9850'],
158+
'Spectral': ['#d53e4f' '#fc8d59' '#fee08b' '#e6f598' '#99d594' '#3288bd'],
159+
'Accent': ['#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f'],
160+
'Dark2': ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02'],
161+
'Paired': ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c'],
162+
'Pastel1': ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc'],
163+
'Pastel2': ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae'],
164+
'Set1': ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33'],
165+
'Set2': ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f'],
166+
'Set3': ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462'],
167+
}
119168

120169
#Raise an error if the n requested is greater than the maximum
121170
if n > maximum_n:
@@ -126,11 +175,11 @@ def color_brewer(color_code, n=6):
126175
if color_code not in schemes:
127176
color_scheme= None
128177
else:
129-
color_scheme = linear_gradient(schemes.get(color_code), n)
130-
131-
132-
#rgb_color_scheme = [hex_to_rgb(hex_code) for hex_code in schemes.get(color_code)]
133-
#color_scheme = [rgb_to_hex(rgb_code) for rgb_code in linear_gradient(rgb_color_scheme, n)]
178+
#Check to make sure that it is not a qualitative scheme
179+
if scheme_info[color_code]=='Qualitative':
180+
raise ValueError("Expanded color support is not available for Qualitative schemes, restrict number of colors to 6")
181+
else:
182+
color_scheme = linear_gradient(schemes.get(color_code), n)
134183
else:
135184
color_scheme = schemes.get(color_code, None)
136185
return color_scheme

0 commit comments

Comments
 (0)