Title: [ENH]: Show parameter names in error message for mismatched array sizes in bar() · Issue #29474 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Show parameter names in error message for mismatched array sizes in bar() · Issue #29474 · matplotlib/matplotlib
X Title: [ENH]: Show parameter names in error message for mismatched array sizes in bar() · Issue #29474 · matplotlib/matplotlib
Description: Problem I lost way too much time figuring out why some plotting code stopped working when I switched from vertical to horizontal bars. I eventually traced the problem down to this minimal repro that produces a very unhelpful error messag...
Open Graph Description: Problem I lost way too much time figuring out why some plotting code stopped working when I switched from vertical to horizontal bars. I eventually traced the problem down to this minimal repro tha...
X Description: Problem I lost way too much time figuring out why some plotting code stopped working when I switched from vertical to horizontal bars. I eventually traced the problem down to this minimal repro tha...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29474
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Show parameter names in error message for mismatched array sizes in bar()","articleBody":"### Problem\n\nI lost way too much time figuring out why some plotting code stopped working when I switched from vertical to horizontal bars. I eventually traced the problem down to this minimal repro that produces a very unhelpful error message from within numpy which it isn't even using directly:\n\n```python\nfrom matplotlib import pyplot as plt\narg_k = [\"foo\", \"bar\" \"baz\"]\narg_n = [1,2,3]\nplt.barh(arg_k, arg_n)\nplt.show()\n```\n\n```\nValueError: shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 2 with shape (3,) and arg 3 \nwith shape (2,).\n```\n\nThe problem is of course the missing comma in the `arg_k` array. In this simplified example the backtrace *does* eventually point at `plt.barh()`, but if the labels were set with `axis.set_yticklabels()` way before the plot call there is no useful context at all.\n\n### Proposed solution\n\nThis seems like something that could be detected already in the `barh()` and other functions and reported immediately (with the appropriate argument names!) instead of requiring users to divine the actual problem from a long backtrace into 3rd party dependencies.","author":{"url":"https://github.com/jansol","@type":"Person","name":"jansol"},"datePublished":"2025-01-15T11:46:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/29474/matplotlib/issues/29474"}
| 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:ceddd42b-4254-d9a4-46d1-7820464105cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 90CE:225DDE:4C8961:660695:6A52F4EB |
| html-safe-nonce | 11c7d6821cf27993b8b0a394b147639a367318a1649d1bc5a1035d016f30fd4d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MENFOjIyNURERTo0Qzg5NjE6NjYwNjk1OjZBNTJGNEVCIiwidmlzaXRvcl9pZCI6IjMwNzM2OTAwMTQyNzE1OTk4NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5ed9a7cf5146366edb41e4184a7c091443d667502f84bad485641de9caf7fcd3 |
| hovercard-subject-tag | issue:2789586757 |
| 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/29474/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d60409f5638c2e687925518231ddb518d9915cb4e75deb10737cdef36938c47d/matplotlib/matplotlib/issues/29474 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d60409f5638c2e687925518231ddb518d9915cb4e75deb10737cdef36938c47d/matplotlib/matplotlib/issues/29474 |
| og:image:alt | Problem I lost way too much time figuring out why some plotting code stopped working when I switched from vertical to horizontal bars. I eventually traced the problem down to this minimal repro tha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jansol |
| 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