'Unable to use "scheme" attribute when plot GeoDataFrame

I am rerunning the code in https://www.kaggle.com/skalskip/using-regression-to-predicting-earnings-in-france under Python 3.6, and in the plotting stage I ran the following code:

fig, ax = plt.subplots(1, figsize=(15,14))
ax.set_title('Salary by Departments', size=32, x = 0.25, y=0.90)
fig.patch.set_facecolor((202/255, 204/255, 206/255))
departments_map.plot(ax=ax, column="SNHM14", cmap=plt.cm.plasma, k=10, legend=True)
leg = ax.get_legend()
ax.set_axis_off()
leg.set_bbox_to_anchor((0., 0., 0.2, 0.45))
leg.set_title("Mean net salary")

I received:

ImportError: PySAL is required to use the 'scheme' keyword

The type of the dataframe departments_map is geopandas.geodataframe.GeoDataFrame.

I did pip install pysal and it showed that Successfully installed pysal-2.0.0. But I rerun again the problem is the same. I referred to the source code of /geopandas/plotting.py and found the souce may be:

...
...
...
    try:
        from pysal.esda.mapclassify import Quantiles, Equal_Interval, Fisher_Jenks
        schemes = {}
        schemes['equal_interval'] = Equal_Interval  
        schemes['quantiles'] = Quantiles    
        schemes['fisher_jenks'] = Fisher_Jenks
        scheme = scheme.lower()
        if scheme not in schemes:
            raise ValueError("Invalid scheme. Scheme must be in the set: %r" % schemes.keys())

        binning = schemes[scheme](values, k)

        return binning

    except ImportError: 
        raise ImportError("PySAL is required to use the 'scheme' keyword")

I think the problem is from pysal.esda.mapclassify and I looked at the Pysal package I have installed, but under the Pysal founder I didn't find the pysal\esda\mapclassify path. Here is how the ..\Python\Lib\site-packages\pysal on my computer looks like:

  • __pycache__
  • explore
  • lib
  • model
  • viz
  • __init__.py

I did find the mapclassify folder but it is under 'viz' instead of 'esda'.

Is it the version problem?

Update: Thank to the answer from @martinfleis I downgraded the pysal into 1.14.4. But now the new error raise:

........
........
  File "F:\Python\lib\site-packages\matplotlib\artist.py", line 881, in _update_property
    raise AttributeError('Unknown property %s' % k)

AttributeError: Unknown property scheme


Solution 1:[1]

PySAL 2.0 has a new structure. There is a fix for GeoPandas coming soon (like today). You can either wait for that (version 0.4.1) or use GeoPandas from master via pip install git+git://github.com/geopandas/geopandas.git. Or alternatively downgrade PySAL to 1.x.

Solution 2:[2]

pip install geopandas==0.4.0

pip install mapclassify

pip install pysal==2.0.0

pip install -U --no-deps mapclassify git+git://github.com/geopandas/geopandas.git@master

Solution 3:[3]

Had the same problem after upgrading GeoPandas to 0.10. So the problem seems to be persistent.

pip install --upgrade pysal==1.14.4

Did the trick for me. Usage context:

gdf.plot(column='impedance', 
            cmap='YlOrRd', 
            label=gdf['impedance'], 
            scheme='quantiles',   **<===========**
            legend=True,
            k=10,
            ec='black',
            lw=.5,
            ax=ax)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 martinfleis
Solution 2 Lucas Marcondes Pavelski
Solution 3 Maartenk