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

plotting issue with splot.esda.lisa_cluster() #139

Closed
jGaboardi opened this issue Jul 30, 2021 · 15 comments
Closed

plotting issue with splot.esda.lisa_cluster() #139

jGaboardi opened this issue Jul 30, 2021 · 15 comments

Comments

@jGaboardi
Copy link
Member

Using splot.esda.lisa_cluster() to plot line-based LISA clusters seems to work with the most recent release of splot (v1.1.4). Here is a notebook demonstrating that the docstring example still works with polygons, but not with lines like it did previously.

@slumnitz
Copy link
Member

slumnitz commented Aug 3, 2021

@jGaboardi is there any error message that shows up?

@jGaboardi
Copy link
Member Author

Nope 😕, no error message or warning. Just an empty plot (but with an intact legend).

@slumnitz
Copy link
Member

slumnitz commented Aug 3, 2021

ok I run into the same issue on macOS, executing lisa_cluster line by line I run into this error:

In [74]:     gdf.assign(cl=labels).plot(column='cl', categorical=True,
    ...:                                k=2, cmap=hmap, linewidth=0.1, ax=ax,
    ...:                                edgecolor='white', legend=legend,
    ...:                                legend_kwds=legend_kwds, **kwargs)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-74-7f905743daea> in <module>
----> 1 gdf.assign(cl=labels).plot(column='cl', categorical=True,
      2                            k=2, cmap=hmap, linewidth=0.1, ax=ax,
      3                            edgecolor='white', legend=legend,
      4                            legend_kwds=legend_kwds, **kwargs)

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/pandas/core/frame.py in assign(self, **kwargs)
   4479 
   4480         for k, v in kwargs.items():
-> 4481             data[k] = com.apply_if_callable(v, data)
   4482         return data
   4483 

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/geopandas/geodataframe.py in __setitem__(self, key, value)
   1320             except TypeError:
   1321                 warnings.warn("Geometry column does not contain geometry.")
-> 1322         super(GeoDataFrame, self).__setitem__(key, value)
   1323 
   1324     #

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   3605         else:
   3606             # set column
-> 3607             self._set_item(key, value)
   3608 
   3609     def _setitem_slice(self, key: slice, value):

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/pandas/core/frame.py in _set_item(self, key, value)
   3777         ensure homogeneity.
   3778         """
-> 3779         value = self._sanitize_column(value)
   3780 
   3781         if (

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/pandas/core/frame.py in _sanitize_column(self, value)
   4502 
   4503         if is_list_like(value):
-> 4504             com.require_length_match(value, self.index)
   4505         return sanitize_array(value, self.index, copy=True, allow_2d=True)
   4506 

/usr/local/Caskroom/miniforge/base/envs/bio/lib/python3.8/site-packages/pandas/core/common.py in require_length_match(data, index)
    529     """
    530     if len(data) != len(index):
--> 531         raise ValueError(
    532             "Length of values "
    533             f"({len(data)}) "

ValueError: Length of values (303) does not match length of index (49)

whereby mask_local_auto produces 303 labels. Maybe this helps and we figure it out bit by bit? Does assign behave differently, did something change in geopandas/ pandas? @martinfleis

@jGaboardi
Copy link
Member Author

Oh! You got an actual error message??

@slumnitz
Copy link
Member

slumnitz commented Aug 3, 2021

@jGaboardi I started debugging lisa_cluster line by line, so we need to resolve the missmatch between the assign and the gdf.

@jGaboardi
Copy link
Member Author

Hmmm. I don't think anything changed within splot here for this release, right? So probably something a dependency?

@martinfleis
Copy link
Member

Does assign behave differently, did something change in geopandas/ pandas?

I am not aware of any change on GeoPandas side regarding assign. Can you track it to a version?

@jGaboardi
Copy link
Member Author

Versions are listed in the bug notebook:

spaghetti : 1.6.2
libpysal  : 4.5.1
esda      : 2.4.1
geopandas : 0.9.0
numpy     : 1.21.1
matplotlib: 3.4.2
splot     : 1.1.4
json      : 2.0.9
scipy     : 1.7.0

@martinfleis
Copy link
Member

It is plotted, it is not empty. Just in white. This makes sense as we hard-code it as edgecolor='white'. If you remove that, it works.

gdf.assign(cl=labels).plot(column='cl', categorical=True,
k=2, cmap=hmap, linewidth=0.1, ax=ax,
edgecolor='white', legend=legend,
legend_kwds=legend_kwds, **kwargs)

I'd say that the code in splot is doing what it is supposed to now. Probably some plotting change in geopandas caused this but we need to fix it here.

@martinfleis
Copy link
Member

Btw, I have no clue how did you get that error @slumnitz

@slumnitz
Copy link
Member

slumnitz commented Aug 4, 2021

we should also test how removing affects polygons instead of lines! Thank you @martinfleis!

@martinfleis
Copy link
Member

I think we should treat LineStrings and Polygons differently under the hood and pass edgecolor to Polygons and not to LineStrings.

@slumnitz
Copy link
Member

slumnitz commented Aug 5, 2021

@jGaboardi, @darribas and @martinfleis what do you think about adding additional tests that warn the user if there is more than one geom_type in the gdf? Has this ever been an issue?

@martinfleis
Copy link
Member

It is technically possible to have mixed type GeoDataFrame and still get contiguity and measure LISA, though I can't think of a use case that would make sense. We can certainly add a warning in that case but I am not worried about that very much.

@jGaboardi
Copy link
Member Author

Resolving in #140.

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

No branches or pull requests

3 participants