Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
The 3-dimensional quiver accepts the argument 'normalize' and 'length'.
%matplotlibnotebookimportmatplotlib.pyplotaspltimportnumpyasnpfig=plt.figure()ax=plt.axes(projection='3d')X,Y=np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10))Z=X**2+Y**2# Gradient Vector Components U and VU,V= (2*X,2*Y)ax.plot_surface(X,Y,Z,cmap='YlGnBu')ax.quiver(X,Y,0,U,V,0,length=1,normalize=True)
This gives the desired output:
However, when using a 2D quiver plot, I get an error. It seems inconsistent to me.
Code for reproduction
%matplotlibnotebookimportmatplotlib.pyplotaspltimportnumpyasnpfig=plt.figure()ax=plt.axes()X,Y=np.meshgrid(np.linspace(-5,5,10),np.linspace(-5,5,10))Z=X**2+Y**2U,V= (2*X,2*Y)ax.contourf(X,Y,Z,cmap='plasma')ax.quiver(X,Y,U,V,normalize=True,length=1)
Actual outcome
AttributeErrorTraceback (mostrecentcalllast)CellIn[70],line1412U,V= (2*X,2*Y)13ax.contourf(X,Y,Z,cmap='plasma')--->14ax.quiver(X,Y,U,V,normalize=True,length=1)FileC:\Python\310\lib\site-packages\matplotlib\__init__.py:1423,in_preprocess_data.<locals>.inner(ax,data,*args,**kwargs)1420 @functools.wraps(func)1421definner(ax,*args,data=None,**kwargs):1422ifdataisNone:->1423returnfunc(ax,*map(sanitize_sequence,args),**kwargs)1425bound=new_sig.bind(ax,*args,**kwargs)1426auto_label= (bound.arguments.get(label_namer)1427orbound.kwargs.get(label_namer))FileC:\Python\310\lib\site-packages\matplotlib\axes\_axes.py:5103,inAxes.quiver(self,*args,**kwargs)5101# Make sure units are handled for x and y values5102args=self._quiver_units(args,kwargs)->5103q=mquiver.Quiver(self,*args,**kwargs)5104self.add_collection(q,autolim=True)5105self._request_autoscale_view()FileC:\Python\310\lib\site-packages\matplotlib\quiver.py:514,inQuiver.__init__(self,ax,scale,headwidth,headlength,headaxislength,minshaft,minlength,units,scale_units,angles,width,color,pivot,*args,**kwargs)512kwargs.setdefault('facecolors',color)513kwargs.setdefault('linewidths', (0,))-->514super().__init__([],offsets=self.XY,offset_transform=self.transform,515closed=False,**kwargs)516self.polykw=kwargs517self.set_UVC(U,V,C)FileC:\Python\310\lib\site-packages\matplotlib\_api\deprecation.py:454,inmake_keyword_only.<locals>.wrapper(*args,**kwargs)448iflen(args)>name_idx:449warn_deprecated(450since,message="Passing the %(name)s %(obj_type)s "451"positionally is deprecated since Matplotlib %(since)s; the "452"parameter will become keyword-only %(removal)s.",453name=name,obj_type=f"parameter of{func.__name__}()")-->454returnfunc(*args,**kwargs)FileC:\Python\310\lib\site-packages\matplotlib\collections.py:1174,inPolyCollection.__init__(self,verts,sizes,closed,**kwargs)1153 @_api.make_keyword_only("3.6",name="closed")1154def__init__(self,verts,sizes=None,closed=True,**kwargs):1155""" 1156 Parameters 1157 ---------- (...) 1172 Forwarded to `.Collection`. 1173 """->1174super().__init__(**kwargs)1175self.set_sizes(sizes)1176self.set_verts(verts,closed)FileC:\Python\310\lib\site-packages\matplotlib\_api\deprecation.py:454,inmake_keyword_only.<locals>.wrapper(*args,**kwargs)448iflen(args)>name_idx:449warn_deprecated(450since,message="Passing the %(name)s %(obj_type)s "451"positionally is deprecated since Matplotlib %(since)s; the "452"parameter will become keyword-only %(removal)s.",453name=name,obj_type=f"parameter of{func.__name__}()")-->454returnfunc(*args,**kwargs)FileC:\Python\310\lib\site-packages\matplotlib\collections.py:202,inCollection.__init__(self,edgecolors,facecolors,linewidths,linestyles,capstyle,joinstyle,antialiaseds,offsets,offset_transform,norm,cmap,pickradius,hatch,urls,zorder,**kwargs)199self._offset_transform=offset_transform201self._path_effects=None-->202self._internal_update(kwargs)203self._paths=NoneFileC:\Python\310\lib\site-packages\matplotlib\artist.py:1186,inArtist._internal_update(self,kwargs)1179def_internal_update(self,kwargs):1180""" 1181 Update artist properties without prenormalizing them, but generating 1182 errors as if calling `set`. 1183 1184 The lack of prenormalization is to maintain backcompatibility. 1185 """->1186returnself._update_props(1187kwargs,"{cls.__name__}.set() got an unexpected keyword argument "1188"{prop_name!r}")FileC:\Python\310\lib\site-packages\matplotlib\artist.py:1160,inArtist._update_props(self,props,errfmt)1158func=getattr(self,f"set_{k}",None)1159ifnotcallable(func):->1160raiseAttributeError(1161errfmt.format(cls=type(self),prop_name=k))1162ret.append(func(v))1163ifret:AttributeError:Quiver.set()gotanunexpectedkeywordargument'normalize'
Expected outcome
Without the arguments, I get the plot as expected, however I want the vectors to be normalized to a certain length.
Additional information
No response
Operating system
Windows
Matplotlib Version
3.6.2
Matplotlib Backend
nbagg
Python version
3.10.8
Jupyter version
6.5.2
Installation
pip