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

Shape elements cannot display legends #450

Open
poplarShift opened this issue Mar 26, 2020 · 5 comments
Open

Shape elements cannot display legends #450

poplarShift opened this issue Mar 26, 2020 · 5 comments

Comments

@poplarShift
Copy link

poplarShift commented Mar 26, 2020

The following throws an error if legend labels are requested in the matplotlib backend:

import geoviews as gv, holoviews as hv
hv.extension('matplotlib')
r = hv.renderer('matplotlib')
gv.Shape(LineString(([0, 0], [1, 1])), label='a').opts(show_legend=True) * gv.Points([])

or

gv.Shape(Polygon(([0, 0], [1, 1], [0.5, 1])), label='a').opts(show_legend=True) * gv.Points([])

both choke on the fact that the Legend Handler is handed a cartopy FeatureArtist, shown by comparison of the generated matplotlib figure coming out of gv.Shape vs that from gv.Path:

l = gv.Shape(LineString(([0, 0], [1, 1])), label='a').opts(show_legend=False)
fig = hv.render(l)

ax = fig.axes[0]

print(ax.artists)
print(ax.collections)
r.get_plot(l).handles

gives

[<cartopy.mpl.feature_artist.FeatureArtist object at 0x1358f5b50>]
[]

{'fig': <Figure size 288x288 with 1 Axes>,
 'axis': <cartopy.mpl.geoaxes.GeoAxesSubplot at 0x1356c8af0>,
 'bbox_extra_artists': [],
 'artist': <cartopy.mpl.feature_artist.FeatureArtist at 0x135673a00>,
 'title': Text(0.5, 1.0, 'a'),
 'gridlines': <cartopy.mpl.gridliner.Gridliner at 0x135663e50>}

and

l = gv.Path(dict(x=[0, 1], y=[0, 1]), label='a').opts(show_legend=True)
fig = hv.render(l)

ax = fig.axes[0]

print(ax.artists)
print(ax.collections)
r.get_plot(l).handles

gives

[]
[<matplotlib.collections.LineCollection object at 0x1354a5340>]

{'fig': <Figure size 288x288 with 1 Axes>,
 'axis': <cartopy.mpl.geoaxes.GeoAxesSubplot at 0x135338c70>,
 'bbox_extra_artists': [],
 'artist': <matplotlib.collections.LineCollection at 0x135037280>,
 'title': Text(0.5, 1.0, 'a'),
 'gridlines': <cartopy.mpl.gridliner.Gridliner at 0x1355459a0>}

I assume fixing this will either have to have GeoShapePlot hand over something else than FeatureArtist or implement a legend handler that can deal with Feature Artists in some way.

@poplarShift
Copy link
Author

See SciTools/cartopy#334

@poplarShift
Copy link
Author

Also see SciTools/cartopy#1500

@ppwadhwa
Copy link

Are we waiting for this to be merged on cartopy? Is there anything that needs to be done on geoviews?

@jlstevens jlstevens added this to the Version 1.8.2 milestone Aug 17, 2020
@jlstevens
Copy link
Contributor

Assigning to the 1.8.2 milestone which we can bump if the cartopy PR referenced above isn't merged and in a new cartopy release.

@poplarShift
Copy link
Author

I think once the cartopy people get around to checking out my PR there may be some more discussions over there (as the FeatureArtist seems to promise more than it actually does, which may have repercussions on some implementation details for the legend handler), but it should be reasonably straightforward to merge as far as simple legends are concerned. What it doesn't solve for instance is that geoviews Shapes are drawn using the FeatureArtist which does not draw point shapes IIRC, but I can't recall if there's an issue for that somewhere or of there've been recent developments that would address that.

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

5 participants