Open kburchfiel opened 6 months ago
Hi @kburchfiel, thanks for your issue and the example notebook you shared, it's easy to see what you mean! I've tried to look into this, but I can't really figure out what's going on either. All the color lists, bins, indexes, vmin and vmax, it's not that easy to follow, especially when converting from linear to step and back.
I know I added the 'bug' label earlier, but I'm not sure it's really a bug. Linear colormaps and step colormaps are different, for example in the way they treat bins. Maybe it's expected that when you create a StepColormap
directly, it produces different results than if you take a LinearColormap
and use to_step
on it.
We can leave this open for now, maybe somebody else has a good answer here.
One thing I tried to figure out if it has to do with how linear and step treat bins differently, maybe there's something there still.
Thanks for looking into this! Fortunately, the StepColorMap option works great for my needs, so I don't see any urgent need to address this bug (if it's even a bug at all, as you noted). Hopefully this question can help other users who are encountering the same issue, though.
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:
Method 2:
custom_bins_to_step = linear.RdYlBu_10.to_step(index = bins)
Output: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:Method 2 (using previously defined
color_range
andbins
values):Output:
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:
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:
The colors in the above map match those I'm seeing from a folium.Choropleth() call.
Map created with custom_bins_to_step):