-
Notifications
You must be signed in to change notification settings - Fork 368
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
Legends for feature artists #1500
base: main
Are you sure you want to change the base?
Conversation
I've also submitted the CLA now. |
|
||
def get_stylised_paths(self, geoms, feature_crs, projection, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this private.
c.set_clip_path(ax.patch) | ||
c.set_figure(ax.figure) | ||
c.draw(renderer) | ||
def get_geometry(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this too.
warnings.warn('''Unable to determine extent. | ||
Defaulting to global.''') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning should definitely not have a newline and a bunch of whitespace in it. Use plain strings, not a multiline string.
for style in stylised_paths.keys(): | ||
style = dict(style) | ||
facecolor = style.get('facecolor', 'none') | ||
if facecolor not in ('none', 'never') or type(geom) is Polygon: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use isinstance
width=width, height=height, | ||
**style | ||
) | ||
elif type(geom) in (LineString, LinearRing): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use isinstance
|
Fixes #334.
Enables legends for
FeatureArtists
by implementing a legend handler and registering it with matplotlib.This necessitated factoring out some of the code in the
FeatureArtists
'draw
method to make it accessible to the newHandlerFeature
legend handler.As for tests, I haven't looked into how to test legend handling in matplotlib. Can do that though if you think this PR is useful!
Example:
PS:
cb3de4f
draws all legend artists as Polygons, which looks as below, will also respect facecolor options and is much simpler even forLineString
s but may look non-intuitive whenfacecolor
=none
.cb3de4f
adds another if/else clause based on facecolor to decide betweenRectangle
andLine2D
for the legend artist, which looks likePPS:
I have a vague feeling that the legend artists could have been based off of
HandlerPathCollection
since that is what theFeatureArtist
is drawing but I could not find a way to make the right submethods available to the handler since the actual artist is not based offPathCollection
.