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 1 commit
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
14 changes: 14 additions & 0 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,20 @@ 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.

has_LineString = False
try:
for g in iter(tuple(geoms)):
if isinstance(g, sgeom.LineString):
has_LineString = True
break
smartlixx marked this conversation as resolved.
Show resolved Hide resolved
except TypeError:
if isinstance(geoms, sgeom.LineString):
has_LineString = True

if has_LineString:
kwargs['facecolor'] = 'none'
if 'edgecolor' not in kwargs or kwargs['edgecolor'] == 'face':
kwargs['edgecolor'] = mpl.rcParams['patch.edgecolor']
feature = cartopy.feature.ShapelyFeature(geoms, crs, **kwargs)
return self.add_feature(feature, styler=styler)

Expand Down