Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend shows -inf when using lowest in UserDefined #175

Open
dfolch opened this issue Mar 2, 2023 · 4 comments
Open

Legend shows -inf when using lowest in UserDefined #175

dfolch opened this issue Mar 2, 2023 · 4 comments
Assignees

Comments

@dfolch
Copy link
Member

dfolch commented Mar 2, 2023

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);

inf

@sjsrey sjsrey self-assigned this Mar 3, 2023
@sjsrey
Copy link
Member

sjsrey commented Mar 3, 2023

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

image

@sjsrey
Copy link
Member

sjsrey commented Mar 3, 2023

@martinfleis, is this an issue on the geopandas side?

@martinfleis
Copy link
Member

Multiple issues here actually :D.

That TypeError in @sjsrey's post is an issue here. We need to pass lowest to UserDefined here

elif scheme == "userdefined":
classifier = _classifiers[scheme](y, bins)
.

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

ax = gdf.assign(_cl=self.y).plot(
column="_cl",
ax=ax,
cmap=cmap,
edgecolor=border_color,
linewidth=border_width,
scheme=self.name,
legend=legend,
legend_kwds=legend_kwds,
classification_kwds={"bins": self.bins}, # for UserDefined
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.

@jGaboardi
Copy link
Member

@sjsrey Was this issue completely closed with #177?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants