Title: [Bug]: ax.hist density not auto-scaled when using histtype='step' · Issue #24097 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: ax.hist density not auto-scaled when using histtype='step' · Issue #24097 · matplotlib/matplotlib
X Title: [Bug]: ax.hist density not auto-scaled when using histtype='step' · Issue #24097 · matplotlib/matplotlib
Description: Bug summary I need to plot a histogram of some data (generated by numpy.save in binary format) from my work using the matplotlib.axes.Axes.hist function. I noted that the histogram's density axis (when setting density=True) is not automa...
Open Graph Description: Bug summary I need to plot a histogram of some data (generated by numpy.save in binary format) from my work using the matplotlib.axes.Axes.hist function. I noted that the histogram's density axis (...
X Description: Bug summary I need to plot a histogram of some data (generated by numpy.save in binary format) from my work using the matplotlib.axes.Axes.hist function. I noted that the histogram's density ax...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24097
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: ax.hist density not auto-scaled when using histtype='step'","articleBody":"### Bug summary\r\n\r\nI need to plot a histogram of some data (generated by `numpy.save` in binary format) from my work using the `matplotlib.axes.Axes.hist` function. I noted that the histogram's density axis (when setting `density=True`) is not automatically adjusted to fit the whole histogram. \r\n\r\nI played with different combinations of parameters, and noted that the densities changes if you rescale the whole data array, which is counterintuitive as rescaling the data should only affect the x-axis values. I noted that if you set `histtype=\"step\"`, the issue will occur, but is otherwise okay for other `histtype`s.\r\n\r\nI started a github repo for testing this issue [here](https://github.com/coryzh/matplotlib_3.6_hist_bug_report). The `test.npy `file is the data generated from my program.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nscale = 1.2\r\ntest_random = np.random.randn(100000) * scale\r\n\r\nfig, ax = plt.subplots(1, 2, figsize=(20, 10))\r\nhist_bar = ax[0].hist(test_random, bins=100, density=True, histtype=\"bar\")\r\nhist_step = ax[1].hist(test_random, bins=100, density=True, histtype=\"step\")\r\nplt.show()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nHere's the histograms generated using some simulated data. You can play with the `histtype` and `scale` parameters in the code to see the differences. When `scale=1.2`, I got\r\n\r\n\r\n\r\n### Expected outcome\r\nWhen `scale=1`, sometimes the randomised array would lead to identical left and right panel ...\r\n\r\n\r\n\r\n### Additional information\r\n\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\nOS/X\r\n\r\n### Matplotlib Version\r\n\r\n3.6.0\r\n\r\n### Matplotlib Backend\r\n\r\n_No response_\r\n\r\n### Python version\r\n\r\n3.10.4\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/coryzh","@type":"Person","name":"coryzh"},"datePublished":"2022-10-05T13:21:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/24097/matplotlib/issues/24097"}
| 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:014e7f9c-00b5-6800-0713-0d248cbc50cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD06:2F8BFC:7C42BA:A5D415:6A519176 |
| html-safe-nonce | 0fb06d432fb41e2692efabab918898ae5a008ed9415480185fa9549b4b25f4e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDA2OjJGOEJGQzo3QzQyQkE6QTVENDE1OjZBNTE5MTc2IiwidmlzaXRvcl9pZCI6IjQxODQwNDYxNjgxODE5MzY1MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2602cc1ea433ef97a9d5ed8ee64b3a132bbcd6976706f25a73263512f0841714 |
| hovercard-subject-tag | issue:1397786356 |
| 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/24097/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f39593242edeaf6ea086039d89b5cee7467c041c9de11ed380af9281c2e4c78e/matplotlib/matplotlib/issues/24097 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f39593242edeaf6ea086039d89b5cee7467c041c9de11ed380af9281c2e4c78e/matplotlib/matplotlib/issues/24097 |
| og:image:alt | Bug summary I need to plot a histogram of some data (generated by numpy.save in binary format) from my work using the matplotlib.axes.Axes.hist function. I noted that the histogram's density axis (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | coryzh |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width