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

change LineString facecolor to None #1790

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,23 @@ def add_geometries(self, geoms, crs, **kwargs):

"""
styler = kwargs.pop('styler', None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about updating the styler here? You can pass a callable that updates the color that way. You might be able to put the isinstance check in that way and it would act on each geometry then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. But maybe it should be clarified that we only do styler update for LineString when
(1) styler is not set (None); or
(2) facecolor is not set, otherwise we should assume the user wants to fill the LineString by explicitly specifying facecolor.

And, what if user passes a callable to styler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all of that. If a user passes a callable for styler then this should have no effect. You could probably add an if callable(styler): return styler in there somewhere.

This should also get some tests to make sure it is covering those cases you mentioned and that we are taking the right paths.


if not callable(styler) and 'facecolor' not in kwargs:
styler_kw = styler

def styler(geom):
styler_g = styler_kw.copy() if styler_kw else {}

if isinstance(geom, sgeom.LineString):
styler_g['facecolor'] = 'none'
if kwargs.get('edgecolor', 'face') == 'face':
styler_g['edgecolor'] = mpl.rcParams['patch.edgecolor']
else:
styler_g['edgecolor'] = kwargs['edgecolor']
return styler_g
else:
return styler_kw

feature = cartopy.feature.ShapelyFeature(geoms, crs, **kwargs)
return self.add_feature(feature, styler=styler)

Expand Down