Skip to content

add geocolormesh #882

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

Closed
wants to merge 0 commits into from
Closed

add geocolormesh #882

wants to merge 0 commits into from

Conversation

mathause
Copy link
Collaborator

Addresses #880 (partially): Automatically create a cartopy GeoAxis for easier plotting of map data. Works for single plots and for FacetGrids. If a normal pyplot axes is passed, defaults to pcolormesh.

Example:

import xarray as xr
t = xr.tutorial.load_dataset('air_temperature')


# simple plot
t.isel(time=0).air.plot.geocolormesh()
plt.show()


# facet grid, no coastlines
f = t.isel(time=slice(0, 3)).air.plot.geocolormesh(col='time', coastlines=False)

# higher resolution coastlines
for ax in f.axes.flatten():
    ax.coastlines(resolution='50m')

plt.show()

import matplotlib.pyplot as plt

# if a matplotlib axis is passed, defaults to pcolormesh
ax = plt.axes()
t.isel(time=0).air.plot.geocolormesh(ax=ax)
plt.show()

@mathause
Copy link
Collaborator Author

These are the plots from above.

geocolormap1
geocolormap2
geocolormap3

@shoyer
Copy link
Member

shoyer commented Jun 14, 2016

I was trying to avoid getting too much geo-specific functionality in xarray, but this does nicely extend the existing plotting methods, so I think this is a reasonable addition. Anyone else have opinions on this one?

@spencerahill
Copy link
Contributor

@shoyer maybe just a name change then? cartopy obviously is inherently geo-specific. Is it possible that other fields would find the utilities in geocolormesh useful? Or could the geocolormesh functionality be refactored into the existing plotting framework? (Just thinking out loud...not familiar with the plotting codebase at all)

@fmaussion
Copy link
Member

I also agree that this is a not to intrusive and useful "geo-specific" addition. Without looking at the implementation, I also wonder if it would be possible to add the same functionality to the existing framework without adding a specific function? The background is that there are other ways than pcolormesh to plot on a map (see also #657)

@shoyer
Copy link
Member

shoyer commented Jun 15, 2016

I'm pretty sure it's possible to add cartopy axes to a FacetGrid using the subplot_kwds argument already. Unfortunately, I don't have any examples handy since I wrote that code at my last job.

What this code does is add the projection=ccrs.PlateCarree() automatically, along with a few other geo specific niceties. I made that suggestion for cartopy itself (SciTools/cartopy#645) but it hasn't been acted on yet.

I agree that this is a good fit for xarray because the plotting API is difficult to extend externally. One nice way to present this to users could be to make a geoplot accessor that works like the current plot accessor but adds these geo specific options. Then you could write, e.g., data.geoplot.pcolormesh().

@mathause
Copy link
Collaborator Author

Yes is is possible to say subplot_kws=dict(projection=ccrs.PlateCaree(). For a single plot it is not possible to specify the projection (as ax=plt.gca()) in the current implementation. Thus one has to create and pass a geoaxes explicitly.

I like the idea of doing data.geoplot.pcolormesh()

  • We could keep the standard name of the plotting function without the need to make up our own.
  • It is possibly easier to extend it to contour and contourf.
  • We can possibly offer more control over specific cartopy features (although adding coasts is possibly the one thing that we will be able to agree on).

Some questions:

  • Would it also offer data.geoplot.line ect.? There is no point but this would be consistent might be asked for.
  • We would need to think hard about how to extend the current implementation without needing to duplicate it.

@fmaussion
Copy link
Member

We would need to think hard about how to extend the current implementation without needing to duplicate it.

Do you think it would be enough to expose the @_plot2d decorator?

@mathause
Copy link
Collaborator Author

What may be possible: extend @_plot2d with a projection=None and a transform=None keyword (and the handling thereof)*. In geoplot we import @_plot2d set the defaults to projection=ccrs.PlateCaree() and transform=ccrs.PlateCaree(), possibly intercept coastlines from kwargs. I don't know if it is possible to update the defaults without explicitly re-writing the call signature of the function (which may change (but this could possibly be tested)).

* This may conflict with the current ax = plt.gca().

@mathause mathause closed this Aug 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants