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
stem
breaks when I specify the horizontal components with a PyTorch Tensor.
Code for reproduction
importtorchfrommatplotlibimportpyplotaspltx=torch.arange(10.)y= (x*.2*torch.pi).sin()plt.plot(x,y)# worksplt.stem(x,y)# breaksplt.stem(x.numpy(),y)# works
Actual outcome
TypeError:min()receivedaninvalidcombinationofarguments-got (out=NoneType,axis=NoneType, ),butexpectedoneof:* ()* (Tensorother)* (intdim,boolkeepdim=False)didn'tmatchbecausesomeofthekeywordswereincorrect:out,axis* (namedim,boolkeepdim=False)didn'tmatchbecausesomeofthekeywordswereincorrect:out,axis
Full traceback
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)CellIn[50],line75y= (x*.2*torch.pi).sin()6plt.plot(x,y)# works---->7plt.stem(x,y)# breaks8plt.stem(x.numpy(),y)# worksFile [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/pyplot.py:4085](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/pyplot.py#line=4084), in stem(linefmt, markerfmt, basefmt, bottom, label, orientation, data, *args)4074 @_copy_docstring_and_deprecators(Axes.stem)4075defstem(4076*args:ArrayLike|str, (...)4083data=None,4084 )->StemContainer:->4085returngca().stem(4086*args,4087linefmt=linefmt,4088markerfmt=markerfmt,4089basefmt=basefmt,4090bottom=bottom,4091label=label,4092orientation=orientation,4093**({"data":data}ifdataisnotNoneelse {}),4094 )File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/__init__.py:1521](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/__init__.py#line=1520), in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)1518 @functools.wraps(func)1519definner(ax,*args,data=None,**kwargs):1520ifdataisNone:->1521returnfunc(1522ax,1523*map(cbook.sanitize_sequence,args),1524**{k:cbook.sanitize_sequence(v)fork,vinkwargs.items()})1526bound=new_sig.bind(ax,*args,**kwargs)1527auto_label= (bound.arguments.get(label_namer)1528orbound.kwargs.get(label_namer))File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/axes/_axes.py:3216](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/axes/_axes.py#line=3215), in Axes.stem(self, linefmt, markerfmt, basefmt, bottom, label, orientation, *args)3214marker_x=locs3215marker_y=heads->3216baseline_x= [np.min(locs),np.max(locs)]3217baseline_y= [bottom,bottom]3219markerline,=self.plot(marker_x,marker_y,3220color=markercolor,linestyle=markerstyle,3221marker=markermarker,label="_nolegend_")File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3301](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py#line=3300), in min(a, axis, out, keepdims, initial, where)3189 @array_function_dispatch(_min_dispatcher)3190defmin(a,axis=None,out=None,keepdims=np._NoValue,initial=np._NoValue,3191where=np._NoValue):3192""" 3193 Return the minimum of an array or minimum along an axis. 3194 (...) 3299 6 3300 """->3301return_wrapreduction(a,np.minimum,'min',axis,None,out,3302keepdims=keepdims,initial=initial,where=where)File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:84](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py#line=83), in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)82returnreduction(axis=axis,dtype=dtype,out=out,**passkwargs)83else:--->84returnreduction(axis=axis,out=out,**passkwargs)86returnufunc.reduce(obj,axis,dtype,out,**passkwargs)TypeError:min()receivedaninvalidcombinationofarguments-got (out=NoneType,axis=NoneType, ),butexpectedoneof:* ()* (Tensorother)* (intdim,boolkeepdim=False)didn'tmatchbecausesomeofthekeywordswereincorrect:out,axis* (namedim,boolkeepdim=False)didn'tmatchbecausesomeofthekeywordswereincorrect:out,axis
Expected outcome
Most of the time, matplotlib is capable of plotting tensors without issues.
Additional information
PyTorch version: 2.7.0
Operating system
No response
Matplotlib Version
3.10.3
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.13.5
Jupyter version
4.4.3
Installation
conda