[BUG] nan_color argument in LinearColorMapper is not used
See original GitHub issueALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)
bokeh.version: 1.3.0 python: 3.7.3 OS: Windows 10 browser: all
Description of expected behavior and the observed behavior
LinearColorMapper has the option to set nan_color. It is however not used. Instead it sets the color of the nan entry to be the lowest color in the range.
In the example below you should see the center region as black, but instead it shows as lowest color in the range.
Complete, minimal, self-contained example code that reproduces the issue
To run, download this file: provinces.zip
import geopandas as gpd
import numpy as np
from bokeh.palettes import Reds
from bokeh.models import GeoJSONDataSource, LinearColorMapper
from bokeh.plotting import figure, show
geodf = gpd.read_file("provinces.geojson")
geodf.loc[6, 'index'] = np.nan
print(geodf)
color_mapper = LinearColorMapper(palette=Reds[9][::-1], nan_color='black')
p = figure()
geo_source = GeoJSONDataSource(geojson=geodf.to_json())
p.patches('xs', 'ys', fill_alpha=1,
fill_color={'field': 'index', 'transform': color_mapper},
line_color='white', line_width=0.5,
source=geo_source)
show(p)
Stack traceback and/or browser JavaScript console output
Data frame that is plotted
Screenshots or screencasts of the bug in action
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
mappers — Bokeh 3.0.3 Documentation
Color to be used if data is NaN or otherwise not mappable. Acceptable values are: any of the named CSS colors, e.g 'green'...
Read more >ValueError: Invalid RGBA argument: What is causing this error?
The error message is misleading. You're getting a ValueError because the shape of colors is wrong, not because an RGBA value is invalid....
Read more >Color Of Nan Changes When Change The Center Value Of Colorbar
LinearColorMapper has the option to set nancolor.It is however not used.Instead it sets the color of the nan entry to be the lowest...
Read more >Python colormap legend - miocittadino.it
Qualitative colormaps: these mix colors with no particular sequence (e. ... Nan Color - this is the color ParaView will use to paint...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, brilliant this small change fixes:
_add_properties
tried to handle this by pre-populating nan arrays for the values but it did not all “orNan” on each value, so nulls that made it over would just overwrite the nans. I will add a PR for this later this week unless someone else gets to it first (needs a unit test that maintains nulls in properties end up as nans in the columns)@bryevdv, great to read you found a solution, thanks for the quick turnaround!