Title: plt.hist fails when data contains nan values · Issue #6992 · matplotlib/matplotlib · GitHub
Open Graph Title: plt.hist fails when data contains nan values · Issue #6992 · matplotlib/matplotlib
X Title: plt.hist fails when data contains nan values · Issue #6992 · matplotlib/matplotlib
Description: I noticed that the histogram plot fails when the data includes nan values import numpy as np import matplotlib.pyplot as plt data = np.random.random(100) data[10] = np.nan plt.hist(data) --------------------------------------------------...
Open Graph Description: I noticed that the histogram plot fails when the data includes nan values import numpy as np import matplotlib.pyplot as plt data = np.random.random(100) data[10] = np.nan plt.hist(data) ----------...
X Description: I noticed that the histogram plot fails when the data includes nan values import numpy as np import matplotlib.pyplot as plt data = np.random.random(100) data[10] = np.nan plt.hist(data) ----------...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/6992
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"plt.hist fails when data contains nan values","articleBody":"I noticed that the histogram plot fails when the data includes nan values\n\n```\nimport numpy as np\nimport matplotlib.pyplot as plt\ndata = np.random.random(100)\ndata[10] = np.nan\nplt.hist(data)\n\n---------------------------------------------------------------------------\nValueError Traceback (most recent call last)\n\u003cipython-input-16-bf65746c0a8a\u003e in \u003cmodule\u003e()\n 3 data = np.random.random(100)\n 4 data[10] = np.nan\n----\u003e 5 plt.hist(data)\n\n//anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)\n 2955 histtype=histtype, align=align, orientation=orientation,\n 2956 rwidth=rwidth, log=log, color=color, label=label,\n-\u003e 2957 stacked=stacked, data=data, **kwargs)\n 2958 finally:\n 2959 ax.hold(washold)\n\n//anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)\n 1817 warnings.warn(msg % (label_namer, func.__name__),\n 1818 RuntimeWarning, stacklevel=2)\n-\u003e 1819 return func(ax, *args, **kwargs)\n 1820 pre_doc = inner.__doc__\n 1821 if pre_doc is None:\n\n//anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)\n 5983 # this will automatically overwrite bins,\n 5984 # so that each histogram uses the same bins\n-\u003e 5985 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)\n 5986 m = m.astype(float) # causes problems later if it's an int\n 5987 if mlast is None:\n\n//anaconda/lib/python2.7/site-packages/numpy/lib/function_base.pyc in histogram(a, bins, range, normed, weights, density)\n 500 if mn \u003e mx:\n 501 raise ValueError(\n--\u003e 502 'max must be larger than min in range parameter.')\n 503 if not np.all(np.isfinite([mn, mx])):\n 504 raise ValueError(\n\nValueError: max must be larger than min in range parameter.\n```\n\nOr is that intended behavior to make sure people notice that they have faulty values in their data?\n\nIt is apparently related to the determination of range, so it would be very easy to fix\n\n```\n--- a/lib/matplotlib/axes/_axes.py\n+++ b/lib/matplotlib/axes/_axes.py\n@@ -6150,8 +6150,8 @@ class Axes(_AxesBase):\n xmax = -np.inf\n for xi in x:\n if len(xi) \u003e 0:\n- xmin = min(xmin, xi.min())\n- xmax = max(xmax, xi.max())\n+ xmin = min(xmin, np.nanmin(xi))\n+ xmax = max(xmax, np.nanmax(xi))\n bin_range = (xmin, xmax)\n\n```\n\nHowever, with this fix one gets a warning when plotting data with nans, but this is already addressed in #6483. \n\nMax\n","author":{"url":"https://github.com/maahn","@type":"Person","name":"maahn"},"datePublished":"2016-08-28T01:05:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/6992/matplotlib/issues/6992"}
| 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:dd6dfab1-e45a-6a88-9836-c4697e6e6c60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A686:11304E:18BF920:220B23C:6A53EAD0 |
| html-safe-nonce | 8ff4d7f86ced9fc25c921c86e7728b720e9b33ee937f1de3027e9324f7b7028f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjg2OjExMzA0RToxOEJGOTIwOjIyMEIyM0M6NkE1M0VBRDAiLCJ2aXNpdG9yX2lkIjoiNTI0Mzc4MjMyNjA0MzIyNTEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e6cab08f7d0057fd3b555097a48501115f9d55727a5653de2bb5bd975063855a |
| hovercard-subject-tag | issue:173623268 |
| 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/6992/issue_layout |
| twitter:image | https://opengraph.githubassets.com/76519cc021c5073db50460c3998de660dfc0ccb9bf026b0a51b42f48c6e06e94/matplotlib/matplotlib/issues/6992 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/76519cc021c5073db50460c3998de660dfc0ccb9bf026b0a51b42f48c6e06e94/matplotlib/matplotlib/issues/6992 |
| og:image:alt | I noticed that the histogram plot fails when the data includes nan values import numpy as np import matplotlib.pyplot as plt data = np.random.random(100) data[10] = np.nan plt.hist(data) ----------... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maahn |
| 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