Title: Better deal with Numpy array subclasses in methods other than plot and scatter · Issue #5896 · matplotlib/matplotlib · GitHub
Open Graph Title: Better deal with Numpy array subclasses in methods other than plot and scatter · Issue #5896 · matplotlib/matplotlib
X Title: Better deal with Numpy array subclasses in methods other than plot and scatter · Issue #5896 · matplotlib/matplotlib
Description: The plot and scatter methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units): In [1]: from astropy import units as u In [2]: import matplotlib.pyplot as plt In [3]: fig = plt.figure() ...
Open Graph Description: The plot and scatter methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units): In [1]: from astropy import units as u In [2]: import matplotlib.p...
X Description: The plot and scatter methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units): In [1]: from astropy import units as u In [2]: import matplotlib.p...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/5896
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better deal with Numpy array subclasses in methods other than plot and scatter","articleBody":"The `plot` and `scatter` methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units):\n\n``` python\nIn [1]: from astropy import units as u\n\nIn [2]: import matplotlib.pyplot as plt\n\nIn [3]: fig = plt.figure()\n\nIn [4]: ax = fig.add_subplot(1,1,1)\n\nIn [5]: x = [1,2] * u.m\n\nIn [6]: y = [3,4] * u.m\n\nIn [7]: ax.plot(x,y)\nOut[7]: [\u003cmatplotlib.lines.Line2D at 0x107f00048\u003e]\n\nIn [8]: ax.scatter(x, y)\nOut[8]: \u003cmatplotlib.collections.PathCollection at 0x107f00ba8\u003e\n```\n\nHowever, other methods such as `axhline` and `axvline` do not:\n\n``` python\nIn [9]: z = 4 * u.m\n\nIn [10]: ax.axhline(z)\n---------------------------------------------------------------------------\nUnitsError Traceback (most recent call last)\n\u003cipython-input-10-39d10b51e434\u003e in \u003cmodule\u003e()\n----\u003e 1 ax.axhline(z)\n\n/Users/tom/miniconda3/envs/production35/lib/python3.5/site-packages/matplotlib/axes/_axes.py in axhline(self, y, xmin, xmax, **kwargs)\n 744 self._process_unit_info(ydata=y, kwargs=kwargs)\n 745 yy = self.convert_yunits(y)\n--\u003e 746 scaley = (yy \u003c ymin) or (yy \u003e ymax)\n 747 \n 748 trans = self.get_yaxis_transform(which='grid')\n\n/Users/tom/miniconda3/envs/production35/lib/python3.5/site-packages/astropy/units/quantity.py in __array_prepare__(self, obj, context)\n 344 \"argument is not a quantity (unless the \"\n 345 \"latter is all zero/infinity/nan)\"\n--\u003e 346 .format(function.__name__))\n 347 except TypeError:\n 348 # _can_have_arbitrary_unit failed: arg could not be compared\n\nUnitsError: Can only apply 'less' function to dimensionless quantities when other argument is not a quantity (unless the latter is all zero/infinity/nan)\n```\n\nIt would be nice to try and make these methods also support Numpy array sub-classes.\n","author":{"url":"https://github.com/astrofrog","@type":"Person","name":"astrofrog"},"datePublished":"2016-01-21T22:55:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/5896/matplotlib/issues/5896"}
| 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:db9229be-56d8-10bf-00c1-235bef16d989 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B6A:29681E:4CFB5D4:6BBC889:6A54FED4 |
| html-safe-nonce | 76799f85da8a47e9662ccf8354a5988c0055fc20b62ad54c387381fc31b798d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjZBOjI5NjgxRTo0Q0ZCNUQ0OjZCQkM4ODk6NkE1NEZFRDQiLCJ2aXNpdG9yX2lkIjoiODg0OTAyNDEzNjUyMzM0OTcxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9d58e4c49bd9ba5422e7c2dd178e6ac1176d3e25159ecb7f4281681518b987f5 |
| hovercard-subject-tag | issue:128040867 |
| 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/matplotlib/matplotlib/5896/issue_layout |
| twitter:image | https://opengraph.githubassets.com/575dd9d7ee2a3af823344d2195cba58b77f8fa73359eff820e24a4e3d50c3c52/matplotlib/matplotlib/issues/5896 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/575dd9d7ee2a3af823344d2195cba58b77f8fa73359eff820e24a4e3d50c3c52/matplotlib/matplotlib/issues/5896 |
| og:image:alt | The plot and scatter methods now deal nicely with Numpy array sub-classes, such as Astropy quantities (which have attached units): In [1]: from astropy import units as u In [2]: import matplotlib.p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | astrofrog |
| hostname | github.com |
| expected-hostname | github.com |
| None | eae2aab99907699a22d2c8449aa683ca74454fca87211b98f7c7b722086b2839 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| 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 | 6a35ab858be185cd86d12b93a43bccf34e8d8536 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width