color issue with world map using Bokeh

Hi there,

I modified the geoJSON world map data and added a layer of numbers from a subset of countries and assign colors according to this value. I got the map working, however, the color is a little off. Note I assign the number to be 0 except 5 countries: Austria, China, Indonesia, Japan and Russia. I expect to see different colors only for these regions. However, I observe color changes in a few other places, like Australia, Argentina, US and Canada etc, which clearly has the number right (=0), but colors wrong. Do you have any idea what’s causing this issue? Thanks!

Here’s my code:


from bokeh.io import show, output_notebook, output_file
from bokeh.models import (
GeoJSONDataSource,
HoverTool,
LinearColorMapper
)
from bokeh.plotting import figure
from bokeh.palettes import Viridis6
from collections import OrderedDict
with open(r'countries.geo.count.json', 'r') as f:
geo_source = GeoJSONDataSource(geojson=f.read())
color_mapper = LinearColorMapper(palette=Viridis6)
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"

## full canvas of world countries
p = figure(
width = 800    , height=400    , title='World Countries'    , tools =TOOLS,
x_axis_label='Longitude'    ,
y_axis_label='Latitude'

<a class='attachment' href='//bokeh-discourse-uploads.s3.dualstack.us-east-1.amazonaws.com/original/1X/6a809f048f24deb7abe60e466dcfc47c817e6030.json'>countries.geo.count.json</a> (275 KB)



<a class='attachment' href='//bokeh-discourse-uploads.s3.dualstack.us-east-1.amazonaws.com/original/1X/97f8494a27babffb323a8f9238327ea89a6bdfd6.html'>dist.html</a> (1.68 MB)



<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

,
)
p.grid.grid_line_color = None

p.patches('xs', 'ys', fill_alpha=0.7, fill_color={'field': 'num', 'transform'          : color_mapper}, line_color='white', line_width=0.5
, source=geo_source)
hover = p.select(dict(type=HoverTool))
hover.point_policy = "follow_mouse"
hover.tooltips = OrderedDict([
("Name", "@name"    ),
("umber", "@num"    ),
("(Long, Lat)", "($x, $y)"
),
])
output_file("dist.html", title="Worldwide distribution"
)
show(p)

Hi there,

I just get around this issue by setting fill_alpha=1 in s.patches() function. Do you have any idea what might cause this problem? I created a test file where I added a field of 0 to the original world map file (countries.geo.count.test.json), and recovered the same issue. By changing fill_alpha=1 I can get around it. Do you think it is an issue with the geoJSON file or with Bokeh? Thanks!

countries.geo.count.test.json (275 KB)

···

On Tue, Feb 13, 2018 at 6:58 PM, Pengyao Jiang [email protected] wrote:

Hi there,

I modified the geoJSON world map data and added a layer of numbers from a subset of countries and assign colors according to this value. I got the map working, however, the color is a little off. Note I assign the number to be 0 except 5 countries: Austria, China, Indonesia, Japan and Russia. I expect to see different colors only for these regions. However, I observe color changes in a few other places, like Australia, Argentina, US and Canada etc, which clearly has the number right (=0), but colors wrong. Do you have any idea what’s causing this issue? Thanks!

Here’s my code:



from [bokeh.io](http://bokeh.io) import show, output_notebook, output_file
from bokeh.models import (
GeoJSONDataSource,
HoverTool,
LinearColorMapper
)
from bokeh.plotting import figure
from bokeh.palettes import Viridis6
from collections import OrderedDict
with open(r'countries.geo.count.json', 'r') as f:
geo_source = GeoJSONDataSource(geojson=f.
read())
color_mapper = LinearColorMapper(palette=
Viridis6)
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"

## full canvas of world countries
p = figure(
width = 800    , height=400    , title='World Countries'    , tools =TOOLS,
x_axis_label='Longitude'    ,
y_axis_label='Latitude'
,
)
p.grid.grid_line_color = None

p.patches('xs', 'ys', fill_alpha=0.7, fill_color={'field': 'num', 'transform'          : color_mapper}, line_color='white', line_width=0.5
, source=geo_source)
hover = p.select(dict(type=HoverTool))
hover.point_policy = "follow_mouse"
hover.tooltips = OrderedDict([
("Name", "@name"    ),
("umber", "@num"    ),
("(Long, Lat)", "($x, $y)"
),
])
output_file("dist.html", title="Worldwide distribution"
)
show(p)

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/18dca0c6-4c92-4248-b4cf-bfbf1198e76a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.