BUG: Choropleth mapping seems scrambled with empty classes
See original GitHub issue-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of geopandas.
-
(optional) I have confirmed this bug exists on the master branch of geopandas.
Code Sample, a copy-pastable example
from pysal.lib import examples
import mapclassify
import geopandas
import matplotlib.pyplot as plt
mx_ex = examples.load_example('mexico')
mx = geopandas.read_file(mx_ex.get_file_list()[0])
years = ['PCGDP1940', 'PCGDP1960', 'PCGDP1980', 'PCGDP2000']
pooled = mapclassify.Pooled(mx[years])
f, axs = plt.subplots(2, 2, figsize=(12, 12))
axs = axs.flatten()
for i, y in enumerate(years):
mx.plot(
y,
scheme='UserDefined',
classification_kwds={
'bins': pooled.global_classifier.bins
},
legend=True,
ax=axs[i]
)
axs[i].set_axis_off()
axs[i].set_title(y)
plt.tight_layout()
plt.show()
Problem description
The current behaviour generates a scrambled ledend when there aren’t values in any of the categories. Ideally, the same legend and classification should appear with the UserDefined
classifier whether there are values or not.
Expected Output
Uniform legend across the four maps. Instead, this is the figure created:
Output of geopandas.show_versions()
This is run on the gds_env:6.1
, versions info below:
SYSTEM INFO
-----------
python : 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27) [GCC 9.3.0]
executable : /opt/conda/bin/python
machine : Linux-5.4.0-77-generic-x86_64-with-glibc2.10
GEOS, GDAL, PROJ INFO
---------------------
GEOS : 3.9.1
GEOS lib : /opt/conda/lib/libgeos_c.so
GDAL : 3.2.1
GDAL data dir: /opt/conda/share/gdal
PROJ : 7.2.0
PROJ data dir: /opt/conda/share/proj
PYTHON DEPENDENCIES
-------------------
geopandas : 0.9.0
pandas : 1.2.3
fiona : 1.8.18
numpy : 1.20.1
shapely : 1.7.1
rtree : 0.9.7
pyproj : 3.0.1
matplotlib : 3.3.4
mapclassify: 2.4.2
geopy : 2.1.0
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
geoalchemy2: 0.8.4
pyarrow : 3.0.0
pygeos : 0.9
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Choropleth Maps - A Guide to Data Classification
A choropleth map uses different shading and colors based on quantitative data. But the problem for choropleth maps is: There are so many...
Read more >Showing no error but blank in choropleth map using folium
I am getting a blank output from the choropleth map. I have tried different versions of joining jsan data but nothing working as...
Read more >Choropleth Mapping — Geographic Data Science with Python
At the time of writing, there is a bug in geopandas plotting that scrambles the legend and classification in cases when there are...
Read more >STAT 6560 Graphical Methods Spring Semester 2011 - Utah State ...
4.1.1 Choropleth Maps in R . . ... In this course, we will start with presentation graphics, ... slope and intercept of the...
Read more >Choropleth Maps
The form of this histogram suggests that 3 or 4 data classes seem most appropriate. Lacking any other insight, the “dips/gaps” suggest natural...
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 Free
Top 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
The colormap inconsistency should be fixed by #2019. The legend labels need to be handled separately.
I think a
min
keyword solves the Mexico example, but I don’t think it solves the case where the lowest 2 (or more) bins are empty; or multiple upper end bins are empty.