Title: Range determination for data with NaNs · Issue #6483 · matplotlib/matplotlib · GitHub
Open Graph Title: Range determination for data with NaNs · Issue #6483 · matplotlib/matplotlib
X Title: Range determination for data with NaNs · Issue #6483 · matplotlib/matplotlib
Description: I notice that this code will plot with warnings: from matplotlib import pyplot as plt from numpy import NaN plt.hist([1, NaN, 4], range=[0,5]) /Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:229: RuntimeWarni...
Open Graph Description: I notice that this code will plot with warnings: from matplotlib import pyplot as plt from numpy import NaN plt.hist([1, NaN, 4], range=[0,5]) /Users/trish/anaconda/lib/python2.7/site-packages/nump...
X Description: I notice that this code will plot with warnings: from matplotlib import pyplot as plt from numpy import NaN plt.hist([1, NaN, 4], range=[0,5]) /Users/trish/anaconda/lib/python2.7/site-packages/nump...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/6483
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Range determination for data with NaNs","articleBody":"I notice that this code will plot with warnings:\n\n``` python\nfrom matplotlib import pyplot as plt\nfrom numpy import NaN\nplt.hist([1, NaN, 4], range=[0,5])\n```\n\n```\n/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:229: RuntimeWarning: invalid value encountered in greater_equal\n keep = (tmp_a \u003e= mn)\n/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:230: RuntimeWarning: invalid value encountered in less_equal\n keep \u0026= (tmp_a \u003c= mx)\n```\n\nWhereas this code ends up with an error because of how the range is determined:\n\n``` python\nfrom matplotlib import pyplot as plt\nfrom numpy import NaN\nplt.hist([1, NaN, 4])\n```\n\n```\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n File \"/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py\", line 2958, in hist\n stacked=stacked, data=data, **kwargs)\n File \"/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py\", line 1812, in inner\n return func(ax, *args, **kwargs)\n File \"/Users/trish/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py\", line 6010, in hist\n m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)\n File \"/Users/trish/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py\", line 176, in histogram\n 'max must be larger than min in range parameter.')\nAttributeError: max must be larger than min in range parameter.\n```\n\nIf we're willing to forgive NaNs in the first case and just plot while ignoring them, wouldn't it also make sense to ignore them in the range computation? Or if that's a bad idea, maybe we could return an error that makes it clear to the user that the problem was NaNs in the data?\n\nThe friend who showed this to me was stumped by the error message because his data was huge and he had no idea it contained NaNs. When he saw that AttributeError he just thought \"But I'm letting matplotlib decide the range, how can it be wrong?\"\n","author":{"url":"https://github.com/TrishGillett","@type":"Person","name":"TrishGillett"},"datePublished":"2016-05-26T22:27:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":19},"url":"https://github.com/6483/matplotlib/issues/6483"}
| 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:c5919958-137e-a430-ab10-9a4fcf8a7062 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D4D8:2F9C11:6AC6BF:8E315E:6A541689 |
| html-safe-nonce | ec1dcdaa33af3ae759e4ec8492b01ebd8d8a09d1f13251cbfd87e81d45a6ef92 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEQ4OjJGOUMxMTo2QUM2QkY6OEUzMTVFOjZBNTQxNjg5IiwidmlzaXRvcl9pZCI6Ijc2NjAxNTkyNTc1MDIwMjk0NDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 08600372f6c446d187dd09eb392fa163d7e37cc3c6bc330c1d07f0cd12fe9dee |
| hovercard-subject-tag | issue:157092920 |
| 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/6483/issue_layout |
| twitter:image | https://opengraph.githubassets.com/76c8c308c064ccfd21d4af1ada082ff61f9fe43a6991172eaa8f0d78e091b09d/matplotlib/matplotlib/issues/6483 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/76c8c308c064ccfd21d4af1ada082ff61f9fe43a6991172eaa8f0d78e091b09d/matplotlib/matplotlib/issues/6483 |
| og:image:alt | I notice that this code will plot with warnings: from matplotlib import pyplot as plt from numpy import NaN plt.hist([1, NaN, 4], range=[0,5]) /Users/trish/anaconda/lib/python2.7/site-packages/nump... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TrishGillett |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width