mapclassify
mapclassify copied to clipboard
Legend shows -inf when using lowest in UserDefined
When using the lowest parameter to create user defined classes, the plot shows -inf.
mapclassify: 2.5.0 geopandas: 0.12.2
# read in some polygons
data = gpd.read_file('https://www2.census.gov/geo/tiger/TIGER2018/STATE/tl_2018_us_state.zip')
data = data.loc[~data.NAME.isin(['Alaska','Hawaii','Puerto Rico','United States Virgin Islands','Commonwealth of the Northern Mariana Islands','Guam','American Samoa']),]
# Create some fake percentages without high or low values
data['mid_vals'] = np.random.uniform(0.3, 0.7, data.shape[0])
# Create user defined bins at 10% intervals
ten_pct_bins = mapclassify.UserDefined(data.mid_vals,
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
lowest=0)
UserDefined
Interval Count
--------------------
[0.00, 0.10] | 0
(0.10, 0.20] | 0
(0.20, 0.30] | 0
(0.30, 0.40] | 15
(0.40, 0.50] | 5
(0.50, 0.60] | 13
(0.60, 0.70] | 16
(0.70, 0.80] | 0
(0.80, 0.90] | 0
(0.90, 1.00] | 0
# Plot the map
ten_pct_bins.plot(data, legend=True);

I think the issue is that the lowest keyword argument is not getting passed through in the GeoDataFrame.plot call:

@martinfleis, is this an issue on the geopandas side?
Multiple issues here actually :D.
That TypeError in @sjsrey's post is an issue here. We need to pass lowest to UserDefined here https://github.com/pysal/mapclassify/blob/34341a22db968b42bcc21b52d4bcf32a0a3e7098/mapclassify/_classify_API.py#L190-L191.
But the reported issue is maybe a different one because it does not use geopandas directly but via our MapClassifier.plot method, so it may be something there. In here https://github.com/pysal/mapclassify/blob/34341a22db968b42bcc21b52d4bcf32a0a3e7098/mapclassify/classifiers.py#L2452-L2461 we need to pass lowest in classification_kwds (for which we need the first issue fixed). Then it should work. Haven't tested it but since geopandas retrives the legend labels via MapClassifier.get_legend_classes, this should be completely fixable on our side here.
@sjsrey Was this issue completely closed with #177?
Closing out. We can reopen if needed.