Title: How to make plt.step() draw between pre-defined bins? · Issue #17529 · matplotlib/matplotlib · GitHub
Open Graph Title: How to make plt.step() draw between pre-defined bins? · Issue #17529 · matplotlib/matplotlib
X Title: How to make plt.step() draw between pre-defined bins? · Issue #17529 · matplotlib/matplotlib
Description: Bug report The docstring for plt.step() states that when where='post': The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]." So if I have a len(2) y array, I should ...
Open Graph Description: Bug report The docstring for plt.step() states that when where='post': The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]." ...
X Description: Bug report The docstring for plt.step() states that when where='post': The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/17529
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to make plt.step() draw between pre-defined bins?","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\nThe docstring for `plt.step()` states that when `where='post'`: \r\n- The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i].\"\r\n\r\nSo if I have a len(2) y array, I should expect the last element to be continued constantly from x[1] to x[2], which means x must be a len(3) array. This makes sense, because x here specifies the edges of the bins. Specifying e.g. `y=[1, 2]` and `x=[0, 1, 4]` doesn't work however:\r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\ndata = [1, 2]\r\nbin_edges = [0, 1, 4]\r\n\r\nfig, ax = plt.subplots()\r\nax.step(data, bin_edges, where='post')\r\n\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n```\r\n File \"test.py\", line 8, in \u003cmodule\u003e\r\n ax.step(data, bin_edges, where='post')\r\n File \"/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/matplotlib/axes/_axes.py\", line 2110, in step\r\n return self.plot(x, y, *args, data=data, **kwargs)\r\n File \"/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/matplotlib/axes/_axes.py\", line 1646, in plot\r\n lines = [*self._get_lines(*args, data=data, **kwargs)]\r\n File \"/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/matplotlib/axes/_base.py\", line 216, in __call__\r\n yield from self._plot_args(this, kwargs)\r\n File \"/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/matplotlib/axes/_base.py\", line 342, in _plot_args\r\n raise ValueError(f\"x and y must have same first dimension, but \"\r\nValueError: x and y must have same first dimension, but have shapes (2,) and (3,)\r\n```\r\n\r\n**Expected outcome**\r\n\r\nThe bins should be drawn between [0, 1] and [1, 4].\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: macos 10.15.4\r\n * Matplotlib version: 3.2.1, installed from pip\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): Qt5Agg\r\n * Python version: 3.8.2\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/dstansby","@type":"Person","name":"dstansby"},"datePublished":"2020-05-28T13:10:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/17529/matplotlib/issues/17529"}
| 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:5808d4b6-0441-6ead-505d-e1a6d0cf52de |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 972A:2C65A3:2F4D28A:40648E8:6A53D3D4 |
| html-safe-nonce | 6e492aff3e6a120240360d0418ed21c19478bfdda4199acb42c1f52350f1d139 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzJBOjJDNjVBMzoyRjREMjhBOjQwNjQ4RTg6NkE1M0QzRDQiLCJ2aXNpdG9yX2lkIjoiNTEwOTc0ODE1MzE4NTQ1NzEwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4dbc4539de1c528f72e6e7654b41848fc910f63f8d3b24eebe306e7bae5cf8fa |
| hovercard-subject-tag | issue:626496221 |
| 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/17529/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2d0a7910d063db50cc5e56369a72daa65bf1004a83bd8211f94e30d96deebda1/matplotlib/matplotlib/issues/17529 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2d0a7910d063db50cc5e56369a72daa65bf1004a83bd8211f94e30d96deebda1/matplotlib/matplotlib/issues/17529 |
| og:image:alt | Bug report The docstring for plt.step() states that when where='post': The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]." ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dstansby |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width