Title: [Bug]: Axe3D text() method does not allow zdir=numpy.array(...) · Issue #30868 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Axe3D text() method does not allow zdir=numpy.array(...) · Issue #30868 · matplotlib/matplotlib
X Title: [Bug]: Axe3D text() method does not allow zdir=numpy.array(...) · Issue #30868 · matplotlib/matplotlib
Description: Bug summary axes.text(..., zdir=zdir) fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() when zdir is a numpy array. The error occurs here: matplotlib/lib/mpl_toolkits/mplot...
Open Graph Description: Bug summary axes.text(..., zdir=zdir) fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() when zdir is a numpy array. The error occurs...
X Description: Bug summary axes.text(..., zdir=zdir) fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() when zdir is a numpy array. The error occurs...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30868
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Axe3D text() method does not allow zdir=numpy.array(...)","articleBody":"### Bug summary\n\n`axes.text(..., zdir=zdir)` fails with `ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()` when zdir is a numpy array. The error occurs here: https://github.com/matplotlib/matplotlib/blob/b70e3246b10d8cf01b87fee358db32c8786aa0b0/lib/mpl_toolkits/mplot3d/art3d.py#L61\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport mpl_toolkits.mplot3d # noqa: F401\n\naxes = plt.axes([0.0, 0.2, 1.0, 0.8], projection='3d')\naxes.text(0, 0, 0, \"zdir=[1,0,0]\", zdir=np.array([1, 0, 0]))\naxes.set_xlabel(\"x axis\")\nplt.show()\n```\n\n### Actual outcome\n\n```python\nTraceback (most recent call last):\n File \".../text3d_error.py\", line 6, in \u003cmodule\u003e\n axes.text(0, 0, 0, \"zdir=[1,0,0]\", zdir=np.array([1, 0, 0]))\n ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../python3.13/site-packages/mpl_toolkits/mplot3d/axes3d.py\", line 1944, in text\n art3d.text_2d_to_3d(text, z, zdir, axlim_clip)\n ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../python3.13/site-packages/mpl_toolkits/mplot3d/art3d.py\", line 222, in text_2d_to_3d\n obj.set_3d_properties(z, zdir, axlim_clip)\n ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/mpl_toolkits/mplot3d/art3d.py\", line 178, in set_3d_properties\n self._dir_vec = get_dir_vector(zdir)\n ~~~~~~~~~~~~~~^^^^^^\n File \".../site-packages/mpl_toolkits/mplot3d/art3d.py\", line 62, in get_dir_vector\n if zdir == 'x':\n ^^^^^^^^^^^\nValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()\n```\n\n### Expected outcome\n\nA 3D box with a label oriented along the x direction.\n\n### Additional information\n\nReplacing the numpy array with a list produces the expected output since `[1, 0, 0] == 'x'` evaluates to `False`.\n\nThe relevant code in main as of 2025-12-16 (post v3.10.8) will still fail.\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.10.3\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/pkienzle","@type":"Person","name":"pkienzle"},"datePublished":"2025-12-16T17:14:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/30868/matplotlib/issues/30868"}
| 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:64ffd13c-225e-189e-4c2a-9cde670c2910 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7AC:14F0B0:17C8DD:1FA940:6A52E457 |
| html-safe-nonce | ed415256bcbc0a5200b29ac0723928ca7f7e13f2fff3643692d36b643a35d0b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0FDOjE0RjBCMDoxN0M4REQ6MUZBOTQwOjZBNTJFNDU3IiwidmlzaXRvcl9pZCI6IjY1MDgxMzI1MzIwMjE4MTQzNTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 47f664485e900043ec3e32cef53018a853c432bc2ce2fd51be588df495cf10f5 |
| hovercard-subject-tag | issue:3735644383 |
| 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/30868/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1380b0cc7d0d6229178fb1e563927aa87d48263e03eec913d8c48808d07afa7/matplotlib/matplotlib/issues/30868 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1380b0cc7d0d6229178fb1e563927aa87d48263e03eec913d8c48808d07afa7/matplotlib/matplotlib/issues/30868 |
| og:image:alt | Bug summary axes.text(..., zdir=zdir) fails with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() when zdir is a numpy array. The error occurs... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkienzle |
| 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