issue_comments: 258695618
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/pull/1079#issuecomment-258695618 | https://api.github.com/repos/pydata/xarray/issues/1079 | 258695618 | MDEyOklzc3VlQ29tbWVudDI1ODY5NTYxOA== | 10050469 | 2016-11-06T17:22:14Z | 2016-11-07T13:57:17Z | MEMBER | After giving this a few more thoughts:
1. if the coordinates are 1D (i.e. the grid is regular in the scipy sense: the coordinates don't have to be evenly spaced), So what do we do with this? @jhamman 's suggestion is to set ``` python import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs import xarray as xr lon, lat = np.linspace(-20, 20, 5), np.linspace(0, 30, 4) lon, lat = np.meshgrid(lon, lat) lon += lat/10 lat += lon/10 da = xr.DataArray(np.arange(20).reshape(4, 5), dims=['y', 'x'], coords = {'lat': (('y', 'x'), lat), 'lon': (('y', 'x'), lon)}) ax = plt.subplot(1, 2, 1, projection=ccrs.PlateCarree()) da.plot.pcolormesh('lon', 'lat', ax=ax, transform=ccrs.PlateCarree(), infer_intervals=False) ax.scatter(lon, lat, transform=ccrs.PlateCarree()) ax.coastlines() ax.set_title('2d irreg case - pcolor') ax = plt.subplot(1, 2, 2, projection=ccrs.PlateCarree()) da.plot.contourf('lon', 'lat', ax=ax, transform=ccrs.PlateCarree()) ax.scatter(lon, lat, transform=ccrs.PlateCarree()) ax.coastlines() ax.set_title('2d irreg case - contourf') ``` Note that one line and one column of data disappeared (so that the colorbar range doesn't correspond to what we see) and the coordinates are not understood as being in the cell center. The advantage of this choice are twofold:
- it's kind of coherent with how Let's call this option "Option A". [edited] I've been playing around with an "Option B", which includes making [\edited] This plot is closer to what I think the grid actually represents, but I am biased towards my usage of xarray (gridded geoscientific models). The disadvantages of option B are: - it adds a bit of complexity - if you think about it, the problem of plotting irregular grids is not really an xarray problem. If there was a perfect way to handle an irregular grids without having bounded coordinates, I guess that matplotlib would have a tool for it. I currently tend to go for option A, since option B is a bit awkward and users who have bounded coordinated available somewhere (as suggested by @ocefpaf ) will have to implement their own plotting routine anyway. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
187208913 |