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

consider geopandas support? #65

Closed
knaaptime opened this issue Nov 18, 2019 · 2 comments
Closed

consider geopandas support? #65

knaaptime opened this issue Nov 18, 2019 · 2 comments

Comments

@knaaptime
Copy link
Contributor

Hi, just dropping by to say this is a fantastic project. Thanks for putting it together!

One thing i'm curious about is whether you'd consider extending support for geopandas plots. I've been toying around and for the most part, proplot works great, though it has some difficulties with legends because of the way geopandas returns fig, ax or soemething (i haven't looked in detail, tbh).

Code sample, a copy-pastable example if possible

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.

# convenience to get data
from geosnap import Community
dc = Community.from_census(msa_fips='47900')

#plot it
f, axs = plot.subplots(ncols=2)

a = dc.gdf[dc.gdf.year==1990].plot(column='median_household_income', ax=axs[0], scheme='quantiles', k=8, legend=True)
dc.gdf[dc.gdf.year==2000].plot(column='median_household_income', ax=axs[1], scheme='quantiles')

axs.format(suptitle='Geopandas Test')

axs[0].format(title='1990')
axs[1].format(title='2000')

axs.legend(a, loc='r', ncols=1, frame=False)

image

Actual result vs. expected result

/Users/knaaptime/anaconda3/envs/geosnap/lib/python3.7/site-packages/proplot/wrappers.py:2116: UserWarning: Legend does not support <matplotlib.axes._subplots.CartesianAxesSubplot object at 0x13288e390> instances.
A proxy artist may be used instead.
See: http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
        leg = mlegend.Legend(self, *zip(*pairs), ncol=ncol, loc=loc, **kwargs)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-7897da7bfa49> in <module>
      9 axs[1].format(title='2000')
     10 
---> 11 axs.legend(a, loc='r', ncols=1, frame=False)
     12 

~/anaconda3/envs/geosnap/lib/python3.7/site-packages/proplot/subplots.py in _iterator(*args, **kwargs)
    276                 ret = []
    277                 for func in objs:
--> 278                     ret.append(func(*args, **kwargs))
    279                 ret = (*ret,)
    280                 if len(self) == 1:

~/anaconda3/envs/geosnap/lib/python3.7/site-packages/proplot/axes.py in legend(self, loc, width, space, *args, **kwargs)
   1153         if loc in ('left','right','top','bottom'):
   1154             ax = self.panel_axes(loc, width=width, space=space, filled=True)
-> 1155             return ax.legend(*args, loc='_fill', **kwargs)
   1156 
   1157         # Fill

~/anaconda3/envs/geosnap/lib/python3.7/site-packages/proplot/axes.py in legend(self, loc, width, space, *args, **kwargs)
   1183 
   1184         # Draw legend
-> 1185         return legend_wrapper(self, *args, loc=loc, **kwargs)
   1186 
   1187     def draw(self, renderer=None, *args, **kwargs):

~/anaconda3/envs/geosnap/lib/python3.7/site-packages/proplot/wrappers.py in legend_wrapper(self, handles, labels, ncol, ncols, center, order, loc, label, title, fontsize, fontweight, fontcolor, color, marker, lw, linewidth, dashes, linestyle, markersize, frameon, frame, **kwargs)
   2199         leg.legendPatch.update(outline) # or get_frame()
   2200         for obj in leg.legendHandles:
-> 2201             obj.update(kw_handle)
   2202         for obj in leg.get_texts():
   2203             obj.update(kw_text)

AttributeError: 'NoneType' object has no attribute 'update'

maybe just a syntax error on my part, but I think this is because of what geopandas is returning...

anyway, thanks again. Looking forward to seeing this package released officially :)

@lukelbd lukelbd added the bug label Nov 26, 2019
@lukelbd
Copy link
Collaborator

lukelbd commented Nov 26, 2019

Thanks for trying out proplot, and for the example! Evidently matplotlib.legend.Legend handles are allowed to be None, never came across this before.

Patch c64eae3 should fix this. Follow the README instructions to uninstall and reinstall.

@lukelbd lukelbd closed this as completed Nov 26, 2019
@lukelbd
Copy link
Collaborator

lukelbd commented Nov 26, 2019

As for geopandas support, proplot should already support most matplotlib wrappers since it is supposed to be a strict superset of matplotlib's functionality. Any errors you get are in fact bugs and should be reported.

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

2 participants