[Python] Whiten the parts that turn black when there is no data in the Choropleth map of Folium.

How to make black colored area in Folium Choropleth white where data is missing; simply set the nan_fill_color

About this article

Currently, I am studying Folium's Choropleth map, but I am having a hard time because many of the ones posted on the net do not work properly. Meanwhile, the ones on this site worked properly and were very helpful.

Let's make a heat map world map of Big Mac Index with Python https://techray.hatenablog.com/entry/2019/12/16/200248

However, on the displayed map, where there is no Big Mac Index (where there is no McDonald's store ?!), it turns black and is a little difficult to see. (Strictly speaking, it is dark gray, but we will proceed as black)

BEFORE (like this) before.png

AFTER I tried whitening black for a moment!

after.png

In this way, it is easy to see that Switzerland has the highest Big Mac.

What changed

I would like you to see the data posted on the original site there, but below, I added a line called nan_fill_color.


#Color the map
folium.Choropleth(
geo_data=geojson,
name='choropleth',
data=df,#Drawing data
columns=['iso_a3', 'dollar_price'], # ["Country code", "Column of values"]
key_on='feature.id',
fill_color='OrRd',#Color specification
fill_opacity=0.7, #Color transparency
line_opacity=1,#Border transparency
nan_fill_color="white",  ####Here, the countries that are not in df are white! !! !!#####
legend_name='big mac index dollar_price' #Usage Guide
).add_to(m)

This was mentioned in the Folium documentation, but it doesn't seem to be well known. https://python-visualization.github.io/folium/modules.html

nan_fill_color (string, default 'black') – Area fill color for nan or missing values. Can pass a hex code, color name.

Those without a value are treated as NaN, and it seems that you can specify the color. In addition to specifying the color, you can also change the transparency.

Other

The data of this Coropress diagram was quite rough. Japan looks like this. .. スクリーンショット 2021-01-11 084242.png After all, it is easy to understand that the boundaries are connected by points and represented by polygons.

Recommended Posts

[Python] Whiten the parts that turn black when there is no data in the Choropleth map of Folium.
There is no switch in python
Unfortunately there is no sense of unity in the where method
Location information data display in Python --Try plotting with the map display library (folium)-
The story of reading HSPICE data in Python
[Python Data Frame] When the value is empty, fill it with the value of another column.
There is a pattern that the program did not stop when using Python threading
Find the part that is 575 from Wikipedia in Python
Not being aware of the contents of the data in python
Let's use the open data of "Mamebus" in Python
What to do when there is no response due to Proxy setting in Python web scraping
Try scraping the data of COVID-19 in Tokyo with Python
[Homology] Count the number of holes in data with Python
Is there a bias in the numbers that appear in the Fibonacci numbers?
When "No changes detected" is displayed in python3 manage.py makemigrations
Let's run Fusion 360 with Python Part 11 Since there is no point along the path in the API, I thought of an alternative
When merging via pull request, there is no committer information in the response from Github API
Play a sound in Python assuming that the keyboard is a piano keyboard
[Python] I wrote the route of the typhoon on the map using folium
How to judge that the cross key is input in Python3
A function that measures the processing time of a method in python
What to do when the value type is ambiguous in Python?
I'm tired of Python, so I analyzed the data with nehan (corona related, is that word now?)
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
When Selenium tells me that the Chrome driver version is different (Python)
[Python] Calculate the number of digits required when filling in 0s [Note]
Note that Python dict returns default value if there is no key
What kind of book is the best-selling "Python Crash Course" in the world?
When issuing an INSERT statement in Python, no such column is displayed
Open an Excel file in Python and color the map of Japan
Find out the name of the method that called it from the method that is python
Notify using Notification Center when the execution environment is macOS in Python
Code reading of faker, a library that generates test data in Python
Get the key for the second layer migration of JSON data in python