Created
November 16, 2018 10:27
-
-
Save dfulu/bff8f77245e2dccb5c43b1e230e487fb to your computer and use it in GitHub Desktop.
Simon's solution to plotting maps from xarray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Simon's solution to plotting maps from xarray | |
''' | |
import cartopy | |
def cyclicContourf(ax, dataFrame, *args, **kwargs): | |
""" | |
make a filled contour by adding a cyclic value for longitude. | |
:param dataFrame: data frame | |
:param args: passsed straight through to contourf | |
:param kwargs: passed straight through to contourf | |
:return: the result.. | |
""" | |
data, lon = cartopy.util.add_cyclic_point(dataFrame.values, dataFrame.longitude.values) | |
cm = ax.contourf(lon,dataFrame.latitude,data,*args,**kwargs) | |
return cm | |
def cyclicContour(ax, dataFrame, *args, **kwargs): | |
""" | |
make a contour by adding a cyclic value for longitude. | |
:param dataFrame: data frame | |
:param args: passsed straight through to contour | |
:param kwargs: passed straight through to contour | |
:return: the result.. | |
""" | |
try: | |
dataFrame.load() | |
except AttributeError: | |
pass | |
data, lon = cartopy.util.add_cyclic_point(dataFrame.values, dataFrame.longitude.values) | |
cm = ax.contour(lon,dataFrame.latitude,data,*args,**kwargs) | |
return cm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment