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

Update geoaxes.py pcolor to catch the ValueError #1476 #1479

Closed
Closed
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
26 changes: 21 additions & 5 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,13 +1757,29 @@ def pcolor(self, *args, **kwargs):
A :class:`~cartopy.crs.Projection`.

"""
result = matplotlib.axes.Axes.pcolor(self, *args, **kwargs)
# In some cases, a ValueError crashes the plot
# if there are other data already plotted by pcolormesh
# while the wrapping cells are plotted by pcolor,
# then the crash prevents the use of pcolormesh which could be
# an option to get around a pcolor crash.
# Managing the exception:
#
try:
result = matplotlib.axes.Axes.pcolor(self, *args, **kwargs)

# Update the datalim for this pcolor.
limits = result.get_datalim(self.transData)
self.update_datalim(limits)
# Update the datalim for this pcolor.
limits = result.get_datalim(self.transData)
self.update_datalim(limits)
self.autoscale_view()
except ValueError:
warnings.warn("Unexpected ValueError in pcolor"
" the pcolor plot artist is removed."
" Some cells could not be transformed"
" in the axis projection.")
for child in self.get_children():
if child is result:
child.remove()

self.autoscale_view()
return result

@_add_transform
Expand Down