Problembranca.utilities.color_brewer raises a non descriptive KeyError if the user requests more colors than the number of colors forming the selected colormap.
For example, RdYlBu is made of 11 individual colors. If the user requests more than 11 colors using the parameter n, this will trigger this error
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-8-32dd8f641e66> in <module>
6 print(branca.utilities.color_brewer('RdYlBu', 11))
7
----> 8 print(branca.utilities.color_brewer('RdYlBu', 12))
9
~\Miniconda3\envs\houselossmodel\lib\site-packages\branca\utilities.py in color_brewer(color_code, n)
150 if not explicit_scheme:
151 # Check to make sure that it is not a qualitative scheme.
--> 152 if scheme_info[base_code] == 'Qualitative':
153 matching_quals = []
154 for key in schemes:
KeyError: 'RdYlBu'
My understanding is that color_brewer is not meant to generate more colors than what is available. For that we can use branca.utilities.linear_gradient.
However, there are two issues I can see with this behaviour:
The KeyError raised is non descriptive and does not point to the real problem
I cannot see a straightforward way to know how many colors a specific colormap has, or to automatically return the maximum number of colors of that colormap
Problem
branca.utilities.color_brewer
raises a non descriptive KeyError if the user requests more colors than the number of colors forming the selected colormap.For example,
RdYlBu
is made of 11 individual colors. If the user requests more than 11 colors using the parametern
, this will trigger this errorMinimal code
Other comments This issue is linked to https://github.com/python-visualization/folium/issues/1270
My understanding is that
color_brewer
is not meant to generate more colors than what is available. For that we can usebranca.utilities.linear_gradient
. However, there are two issues I can see with this behaviour: