Describe the bug
A clear and concise description of what the bug is.
To Reproduce
I'm finding that, when using a set of custom bins within a colormap, the color palette generated with to_step() differs from that created via StepColormap(), even though both of these methods produce the same palette when custom bins are not requested.
Code that demonstrates this discrepancy can be found within this notebook.
Expected behavior
I would expect that the color palettes generated via the following code would be the same: (I recognize that the range represented by each color will change due to the use of custom bins, but I was expecting the actual colors to remain unmodified).
Method 1:
linear_to_step = linear.RdYlBu_10.to_step(n = 10)
Output:
![image](https://private-user-images.githubusercontent.com/32693822/333808588-33b311c3-8e1f-4f70-9357-cd316626d44d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDg1ODgtMzNiMzExYzMtOGUxZi00ZjcwLTkzNTctY2QzMTY2MjZkNDRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU2ZWUxOWFlNzk2ODgzOWU4Y2EwZjFjM2U2YzE2MzA3YzhiNWVkZDI5N2QwMTYxNTM5NmEyMjMxYTE5ZTIxMDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.lVlF55rPJ2eweX3ywYOce5VI3BaaQjWUXnJy0Z12smw)
Method 2:
bins = [-26.57727350868145,
-2.8124548451811697,
-1.3842847014410304,
-0.57942086570913,
0.10509734758955473,
0.803350933220706,
1.5648502030833924,
2.497913057064161,
3.8660584451404807,
5.966706571952004,
25.59683979436641]
custom_bins_to_step = linear.RdYlBu_10.to_step(index = bins)
Output:
![image](https://private-user-images.githubusercontent.com/32693822/333808428-31903fb4-1caf-4d9f-b13f-b70add3f8907.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDg0MjgtMzE5MDNmYjQtMWNhZi00ZDlmLWIxM2YtYjcwYWRkM2Y4OTA3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgyMTE3YmM5Y2U3ZDc3YjdlZDUwMjI2YWMyNGYxNDAzNzdkODFmZmQzOGEyNWFkNmU5ZTdlODM5NWYxMTBiMTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dHhH_8ubsTpOW-tEBcHbZ0xJNe2CQJ02BTX7JIFZLGw)
Note that, when the second method is used, the interior colors within the color palette get much lighter, though the first and last colors are the same. (See the notebook I linked to earlier for a list of the colors.)
Meanwhile, the following methods that use StepColormap produce the same palettes:
Method 1:
color_range = color_brewer('RdYlBu', n = 10)
linear_stepcolormap = StepColormap(colors = color_range)
Output:
![image](https://private-user-images.githubusercontent.com/32693822/333808608-5bccc050-5822-492f-ac15-349020d01b03.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDg2MDgtNWJjY2MwNTAtNTgyMi00OTJmLWFjMTUtMzQ5MDIwZDAxYjAzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg1ZWQ0NmRkOTljN2Y5NjJhNDYxMDAwZTBmMzdkZmRlZTZlMmYxMzY5ZTIwOTM5ZmVkMjZiNmFhMzUzMjE5YTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Jz8yfzyWqWRRkd_ZbrilPXuDwKtjOB8N_okCO4X8ckI)
Method 2 (using previously defined color_range
and bins
values):
custom_bins_stepcolormap = StepColormap(
colors = color_range,
vmin = bins[0], vmax = bins[-1],
index = bins)
Output:
![image](https://private-user-images.githubusercontent.com/32693822/333808501-607453af-701f-4d10-bc56-5f438cdb5cdc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDg1MDEtNjA3NDUzYWYtNzAxZi00ZDEwLWJjNTYtNWY0MzhjZGI1Y2RjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxYjVjZjEzYjMxNDAzNmNkMTZlMGYxODU4N2MzOWNjZjhmN2NjZjNjNjM4YmFkZDEzM2I3ODNjMmRkYzA3N2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.B5pAKzcUVNVHx8i0VoFrNyAb626rPOXD3G0pTcXtwFk)
I'm not sure whether this is a bug or if I'm misunderstanding how the to_step() method works, but either way, your help in getting to_step() to produce the same color palette with custom bins that it does without custom bins would be greatly appreciated. I would also be happy to test out any potential fixes/solutions.
Environment:
- Browser [e.g. chrome, firefox]: Running this code via JupyterLab Desktop and Visual Studio Code. Currently writing this on Chrome
- Jupyter Notebook or html files? Jupyter Notebook
- Python version: 3.12.3
- folium version: 0.16.0
- branca version: 0.7.2
Additional context
When custom_bins_to_step and custom_bins_stepcolormap are fed into the same custom choropleth mapping function, they produce very different results:
Map created with custom_bins_stepcolormap:
![image](https://private-user-images.githubusercontent.com/32693822/333808066-77148bef-83c5-4ab1-baaa-cf25af5ad538.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDgwNjYtNzcxNDhiZWYtODNjNS00YWIxLWJhYWEtY2YyNWFmNWFkNTM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZlMjBlZmVjZTFkNTQ2NDczZjVhOTA0NjA5YTRhYmJjMGY3YmQ1OWFhMDI2YmU5YzYwM2Y2ODE3NDFjOGIxMDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DTj3lVuJQA106zJV-zRjJ6DERHayfbR7irNw3az1yWY)
The colors in the above map match those I'm seeing from a folium.Choropleth() call.
Map created with custom_bins_to_step):
![image](https://private-user-images.githubusercontent.com/32693822/333808183-babf1178-5d2e-4df4-a14e-96c4c87afb6e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4NTQ1NjQsIm5iZiI6MTcyNDg1NDI2NCwicGF0aCI6Ii8zMjY5MzgyMi8zMzM4MDgxODMtYmFiZjExNzgtNWQyZS00ZGY0LWExNGUtOTZjNGM4N2FmYjZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI4VDE0MTEwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZjM2IyNDA3YTRhOWYyYmY0ZDQ1MzI0MTk2NDM1ZDQzNTczMDVmMGMxNjU2M2MzZDNiYzYyZGRkZWFmMTBkZGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.OQntnDKBE_ZLiaXtlLlcBbIkJfCAR49_igIWGD8ltIM)