Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Bug summary
The documentation says thatlinewidths
can befloat or array-like
and it defaults to 1.5, but passing an array-like leads to an error
Code for reproduction
importmatplotlib.pyplotaspltfig=plt.figure()ax=fig.add_subplot(projection='3d')x=range(1,10)ax.scatter(x,x,x,marker='o',s=x,linewidth=x)plt.show()
Actual outcome
Exception:
mpl_toolkits/mplot3d/axes3d.py in do_3d_projection(artist) 469 # avoid passing it to them; call this directly once the 470 # deprecation has expired.--> 471 return artist.do_3d_projection() 472 473 _api.warn_deprecated(matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs) 429 else deprecation_addendum, 430 **kwargs)--> 431 return func(*inner_args, **inner_kwargs) 432 433 return wrappermpl_toolkits/mplot3d/art3d.py in do_3d_projection(self, renderer) 615 616 if len(self._linewidths3d) > 1:--> 617 self._linewidths = self._linewidths3d[z_markers_idx] 618 619 # Re-order itemsTypeError: only integer scalar arrays can be converted to a scalar index
gets raised, from:
matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
Lines 599 to 603 in0d433b4
iflen(self._sizes3d)>1: | |
self._sizes=self._sizes3d[z_markers_idx] | |
iflen(self._linewidths3d)>1: | |
self._linewidths=self._linewidths3d[z_markers_idx] |
This is because the type ofself._sizes3d
isnumpy.ndarray
, but type ofself._linewidths3d
islist
.
Expected outcome
Array-like linewidth works for 3d plots as it does for 2d plots.
Additional information
ax.scatter(x, x, x, marker='o', s=x)
works fine.linewidths
is a list regardless of user input type.- I don't know where linewidths gets converted to a list, but a quick fix is as simple as wrapping it in
np.array
call:self._linewidths = np.array(self._linewidths3d)[z_markers_idx]
(tested that this fixes the issue).
Operating system
No response
Matplotlib Version
3.5.2 but also happens with older versions (3.3.x)
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
pip
Metadata
Metadata
Assignees
Labels
No labels