Title: Adding cyclic point feature · Issue #82 · proplot-dev/proplot · GitHub
Open Graph Title: Adding cyclic point feature · Issue #82 · proplot-dev/proplot
X Title: Adding cyclic point feature · Issue #82 · proplot-dev/proplot
Description: I will address the same issue as for Cartopy (SciTools/cartopy#1402). I would find extremely useful to have an automatic behavior of adding a cyclic point when needed, or at least add an option when doing a plot. Here is an example of wh...
Open Graph Description: I will address the same issue as for Cartopy (SciTools/cartopy#1402). I would find extremely useful to have an automatic behavior of adding a cyclic point when needed, or at least add an option whe...
X Description: I will address the same issue as for Cartopy (SciTools/cartopy#1402). I would find extremely useful to have an automatic behavior of adding a cyclic point when needed, or at least add an option whe...
Opengraph URL: https://github.com/proplot-dev/proplot/issues/82
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding cyclic point feature","articleBody":"I will address the same issue as for **Cartopy** (https://github.com/SciTools/cartopy/issues/1402). I would find extremely useful to have an automatic behavior of adding a **cyclic point** when needed, or at least add an option when doing a plot. \r\n\r\nHere is an example of what I mean (data: [ens_avg_snow.zip](https://github.com/lukelbd/proplot/files/3922831/ens_avg_snow.zip)):\r\n```python\r\nimport xarray as xr\r\nimport proplot as plot\r\n\r\nens_avg_snow = xr.open_dataarray('ens_avg_snow.nc')\r\n\r\nf, axs = plot.subplots(proj='cyl', width=8)\r\nm = axs[0].contourf(ens_avg_snow, cmap='BuRd')\r\nf.colorbar(m)\r\naxs.format(\r\n geogridlinewidth=0.5, geogridcolor='gray8', geogridalpha=0.5, labels=True, \r\n coast=True, ocean=True, oceancolor='gray3', latlim=(20,90),\r\n)\r\n```\r\n\r\n\r\nAs you can see, there is a white line at 0° of longitude. I usually use the `add_cyclic_point` function of `cartopy.utils` but it is not straightforward for DataArrays because it doesn't keep the coordinates and attributes. I recently found some very useful code here: https://github.com/darothen/plot-all-in-ncfile/blob/master/plot_util.py that allows to do it easily with the function `cyclic_dataarray` and there is also a `check_cyclic` that could be used for automatically checking it.\r\n\r\nHere is the function that allows adding a cyclic point (from the link above):\r\n```python\r\nfrom cartopy.util import add_cyclic_point\r\n\r\n# https://github.com/darothen/plot-all-in-ncfile/blob/master/plot_util.py\r\ndef cyclic_dataarray(da, coord='lon'):\r\n \"\"\" Add a cyclic coordinate point to a DataArray along a specified\r\n named coordinate dimension.\r\n \"\"\"\r\n assert isinstance(da, xr.DataArray)\r\n\r\n lon_idx = da.dims.index(coord)\r\n cyclic_data, cyclic_coord = add_cyclic_point(da.values,\r\n coord=da.coords[coord],\r\n axis=lon_idx)\r\n\r\n # Copy and add the cyclic coordinate and data\r\n new_coords = dict(da.coords)\r\n new_coords[coord] = cyclic_coord\r\n new_values = cyclic_data\r\n\r\n new_da = xr.DataArray(new_values, dims=da.dims, coords=new_coords)\r\n\r\n # Copy the attributes for the re-constructed data and coords\r\n for att, val in da.attrs.items():\r\n new_da.attrs[att] = val\r\n for c in da.coords:\r\n for att in da.coords[c].attrs:\r\n new_da.coords[c].attrs[att] = da.coords[c].attrs[att]\r\n\r\n return new_da\r\n```\r\nThus `ens_avg_snow_cyclic = cyclic_dataarray(ens_avg_snow)` allows to make back the previous plot without the white line. Incorporating this directly into **ProPlot** would be nice so that we can just add an option like for example `add_cyclic=True` (just need to be careful about the dimension to do the cyclic or have another way to pass it). \r\n\r\n\r\n","author":{"url":"https://github.com/mickaellalande","@type":"Person","name":"mickaellalande"},"datePublished":"2019-12-04T16:27:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/82/proplot/issues/82"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:533e4a51-e493-feb3-4e2b-951d3301ca25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA20:DF8C:2B80C88:3C6A0C7:697CCFFA |
| html-safe-nonce | 32738e51123dec0a26e91dba97c839592c1c7cd34d01a9a247dc9e8d62128aca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTIwOkRGOEM6MkI4MEM4ODozQzZBMEM3OjY5N0NDRkZBIiwidmlzaXRvcl9pZCI6Ijg2Mjg3MzY5Njg5OTkzNTg0NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ac754862c84c5e000bcbbac0633cf2b62846f0d51ccf828fae720b4ca28d40fe |
| hovercard-subject-tag | issue:532795098 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/proplot-dev/proplot/82/issue_layout |
| twitter:image | https://opengraph.githubassets.com/396fe6508d55e47c477cc4766a316babed9f9297831d3c3c51b0a93c62b7d1d0/proplot-dev/proplot/issues/82 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/396fe6508d55e47c477cc4766a316babed9f9297831d3c3c51b0a93c62b7d1d0/proplot-dev/proplot/issues/82 |
| og:image:alt | I will address the same issue as for Cartopy (SciTools/cartopy#1402). I would find extremely useful to have an automatic behavior of adding a cyclic point when needed, or at least add an option whe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mickaellalande |
| hostname | github.com |
| expected-hostname | github.com |
| None | 885404032cf4ce82316fdeed2c19c8ed247605e75fd124f8b52e9e12339174a9 |
| turbo-cache-control | no-preview |
| go-import | github.com/proplot-dev/proplot git https://github.com/proplot-dev/proplot.git |
| octolytics-dimension-user_id | 108025793 |
| octolytics-dimension-user_login | proplot-dev |
| octolytics-dimension-repository_id | 113293661 |
| octolytics-dimension-repository_nwo | proplot-dev/proplot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 113293661 |
| octolytics-dimension-repository_network_root_nwo | proplot-dev/proplot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 93330c3718e60cdbbb9384d677bd8a01675b3f9c |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width