{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/xarray/issues/2277","repository_url":"https://api.github.com/repos/pydata/xarray","labels_url":"https://api.github.com/repos/pydata/xarray/issues/2277/labels{/name}","comments_url":"https://api.github.com/repos/pydata/xarray/issues/2277/comments","events_url":"https://api.github.com/repos/pydata/xarray/issues/2277/events","html_url":"https://github.com/pydata/xarray/pull/2277","id":340069538,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwNTcxMjI1","number":2277,"title":"[WIP] ENH: Scatter plots of one variable vs another","user":{"login":"yohai","id":6164157,"node_id":"MDQ6VXNlcjYxNjQxNTc=","avatar_url":"https://avatars1.githubusercontent.com/u/6164157?v=4","gravatar_id":"","url":"https://api.github.com/users/yohai","html_url":"https://github.com/yohai","followers_url":"https://api.github.com/users/yohai/followers","following_url":"https://api.github.com/users/yohai/following{/other_user}","gists_url":"https://api.github.com/users/yohai/gists{/gist_id}","starred_url":"https://api.github.com/users/yohai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yohai/subscriptions","organizations_url":"https://api.github.com/users/yohai/orgs","repos_url":"https://api.github.com/users/yohai/repos","events_url":"https://api.github.com/users/yohai/events{/privacy}","received_events_url":"https://api.github.com/users/yohai/received_events","type":"User","site_admin":false},"labels":[{"id":235821884,"node_id":"MDU6TGFiZWwyMzU4MjE4ODQ=","url":"https://api.github.com/repos/pydata/xarray/labels/plotting","name":"plotting","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2018-07-11T02:31:01Z","updated_at":"2019-01-04T17:14:37Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/pydata/xarray/pulls/2277","html_url":"https://github.com/pydata/xarray/pull/2277","diff_url":"https://github.com/pydata/xarray/pull/2277.diff","patch_url":"https://github.com/pydata/xarray/pull/2277.patch"},"body":" - [x] Closes #470 \r\n - [x] Tests added (for all bug fixes or enhancements)\r\n - [x] Tests passed (for all non-documentation changes)\r\n - [x] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API\r\n\r\nSay you have two variables in a `Dataset` and you want to make a scatter plot of one vs the other, possibly using different hues and/or faceting. This is useful if you want to inspect the data to see whether two variables have some underlying relationships between them that you might have missed. It's something that I found myself manually writing the code for quite a few times, so I thought it would be better to have it as a feature. I'm not sure if this is actually useful for other people, but I have the feeling that it probably is. \r\n\r\nFirst, set up dataset with two variables:\r\n\r\n```python\r\nimport xarray as xr\r\nimport numpy as np\r\nimport matplotlib\r\nfrom matplotlib import pyplot as plt\r\n\r\nA = xr.DataArray(np.zeros([3, 11, 4, 4]), dims=[ 'x', 'y', 'z', 'w'],\r\n                  coords=[np.arange(3), np.linspace(0,1,11), np.arange(4), 0.1*np.random.randn(4)])\r\nB = 0.1*A.x**2+A.y**2.5+0.1*A.z*A.w\r\nA = -0.1*A.x+A.y/(5+A.z)+A.w\r\nds = xr.Dataset({'A':A, 'B':B})\r\nds['w'] = ['one', 'two', 'three', 'five']\r\n```\r\nNow, we can plot all values of `A` vs all values of `B`:\r\n```python\r\nplt.plot(A.values.flat,B.values.flat,'.')\r\n```\r\n![a](https://user-images.githubusercontent.com/6164157/42546655-4cce84d8-848c-11e8-8ae0-9249e04137bd.png)\r\n\r\nWhat a mess. Wouldn't it be nice if you could color each point according to the value of some coordinate, say `w`? \r\n```python\r\nds.scatter(x='A',y='B', hue='w')\r\n```\r\n![a](https://user-images.githubusercontent.com/6164157/42546725-9810e4c2-848c-11e8-827d-ae98c57f0ad0.png)\r\nHuh! There seems to be some underlying structure there. Can we also facet over a different coordinate?\r\n```python\r\nds.scatter(x='A',y='B',col='x', hue='w')\r\n```\r\n![a](https://user-images.githubusercontent.com/6164157/42546773-d590caf6-848c-11e8-8095-06216f138a95.png)\r\nor two coordinates?\r\n```python\r\nds.scatter(x='A',y='B',col='x', row='z', hue='w')\r\n```\r\n![a](https://user-images.githubusercontent.com/6164157/42546775-e07a8b96-848c-11e8-98f2-8a05d543b54a.png)\r\n \r\nThe logic is that dimensions that are not faceted/hue are just stacked using `xr.stack` and plotted. Only variables that have exactly the same dimensions are allowed. \r\n\r\nRegarding implementation -- I am certainly not sure about the API and I probably haven't thought about edge cases with missing data or nans or whatnot, so any input would be welcome. Also, there might be a simpler implementation by first using `to_array` and then using existing line plot functions, but I couldn't find it. "},"comment":{"url":"https://api.github.com/repos/pydata/xarray/issues/comments/451507184","html_url":"https://github.com/pydata/xarray/pull/2277#issuecomment-451507184","issue_url":"https://api.github.com/repos/pydata/xarray/issues/2277","id":451507184,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTUwNzE4NA==","user":{"login":"shoyer","id":1217238,"node_id":"MDQ6VXNlcjEyMTcyMzg=","avatar_url":"https://avatars2.githubusercontent.com/u/1217238?v=4","gravatar_id":"","url":"https://api.github.com/users/shoyer","html_url":"https://github.com/shoyer","followers_url":"https://api.github.com/users/shoyer/followers","following_url":"https://api.github.com/users/shoyer/following{/other_user}","gists_url":"https://api.github.com/users/shoyer/gists{/gist_id}","starred_url":"https://api.github.com/users/shoyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoyer/subscriptions","organizations_url":"https://api.github.com/users/shoyer/orgs","repos_url":"https://api.github.com/users/shoyer/repos","events_url":"https://api.github.com/users/shoyer/events{/privacy}","received_events_url":"https://api.github.com/users/shoyer/received_events","type":"User","site_admin":false},"created_at":"2019-01-04T17:14:37Z","updated_at":"2019-01-04T17:14:37Z","author_association":"MEMBER","body":"This generally looks good to me...\r\n\r\nI guess we still use `s=` for indicating marker size?"}}
{"actor":{"display_login":"shoyer"}}