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

Plot categories changed in 0.4.0 #877

Closed
fmaussion opened this issue Dec 11, 2018 · 6 comments
Closed

Plot categories changed in 0.4.0 #877

fmaussion opened this issue Dec 11, 2018 · 6 comments
Labels

Comments

@fmaussion
Copy link
Contributor

My apologies if this was raised before, I haven't had the time to do a proper issue search.

The following code used to create a multicolor plot in geopandas 0.3.0 but not 0.4.0 (or master).

Here the file: clusters.tar.gz

import geopandas as gpd
import matplotlib.pyplot as plt
import matplotlib

print(gpd.__version__)
print(matplotlib.__version__)
df = gpd.read_file('tar://clusters.tar.gz')
df.plot(column='cluster_id', edgecolor='k', cmap='YlOrRd');

Outputs:

0.4.0
3.0.2

/home/mowglie/.pyvirtualenvs/py3/lib/python3.5/site-packages/numpy/core/_methods.py:32: RuntimeWarning: invalid value encountered in reduce
  return umr_minimum(a, axis, None, out, keepdims, initial)
/home/mowglie/.pyvirtualenvs/py3/lib/python3.5/site-packages/numpy/core/_methods.py:28: RuntimeWarning: invalid value encountered in reduce
  return umr_maximum(a, axis, None, out, keepdims, initial)
/home/mowglie/.pyvirtualenvs/py3/lib/python3.5/site-packages/matplotlib/colors.py:512: RuntimeWarning: invalid value encountered in less
  xa[xa < 0] = -1

index

And in 0.3:

0.3.0
3.0.2

/home/mowglie/.pyvirtualenvs/py3/lib/python3.5/site-packages/matplotlib/colors.py:512: RuntimeWarning: invalid value encountered in less
  xa[xa < 0] = -1

index

@fmaussion
Copy link
Contributor Author

(note: also the warning is a bit annoying but this is maybe my data)

@jGaboardi
Copy link
Contributor

@fmaussion
Copy link
Contributor Author

sorry for not seeing that, too much on my plate right now -> removing NaNs also solves the plot.

It used to be more robust in geopandas v0.3, though. Should I leave the issue open?

@martinfleis
Copy link
Member

It is caused by changes in #770. Removing NaNs solves the issue only partially. In 0.3 you those shapes with NaNs were also plotted. I think they should be plotted, just with no value. Opinions?

@fmaussion
Copy link
Contributor Author

I think they should be plotted, just with no value. Opinions?

I agree: like matplotlib's imshow or pcolormesh where NaNs are displayed with white (default) or any color specified by the user in cmap.set_bad()

@martinfleis
Copy link
Member

Got it. mn = values.min() if vmin is None else vmin and mx = values.max() if vmax is None else vmax are both returning nan. That's why it does not plot colours - it is passing range from nan to nan.
Previous version was passing Series, which ignores NaNs in min() and max(). Now it is passing numpy array which returns NaN for min() and max(),
I'll make PR to fix it.

@jdmcbr jdmcbr added the bug label Dec 12, 2018
jdmcbr pushed a commit that referenced this issue Dec 12, 2018
* ignore nan in setting mn and mx

* test if vmin vmax set correctly for array with NaN

* test compatible with older versions

* reference to issue and shorter assert in test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants