-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Milestone
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:
| if zdir == 'x': |
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d # noqa: F401
axes = plt.axes([0.0, 0.2, 1.0, 0.8], projection='3d')
axes.text(0, 0, 0, "zdir=[1,0,0]", zdir=np.array([1, 0, 0]))
axes.set_xlabel("x axis")
plt.show()Actual outcome
Traceback (most recent call last):
File ".../text3d_error.py", line 6, in <module>
axes.text(0, 0, 0, "zdir=[1,0,0]", zdir=np.array([1, 0, 0]))
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../python3.13/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 1944, in text
art3d.text_2d_to_3d(text, z, zdir, axlim_clip)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../python3.13/site-packages/mpl_toolkits/mplot3d/art3d.py", line 222, in text_2d_to_3d
obj.set_3d_properties(z, zdir, axlim_clip)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/mpl_toolkits/mplot3d/art3d.py", line 178, in set_3d_properties
self._dir_vec = get_dir_vector(zdir)
~~~~~~~~~~~~~~^^^^^^
File ".../site-packages/mpl_toolkits/mplot3d/art3d.py", line 62, in get_dir_vector
if zdir == 'x':
^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()Expected outcome
A 3D box with a label oriented along the x direction.
Additional information
Replacing the numpy array with a list produces the expected output since [1, 0, 0] == 'x' evaluates to False.
The relevant code in main as of 2025-12-16 (post v3.10.8) will still fail.
Operating system
No response
Matplotlib Version
3.10.3
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None