Hi Matplotlib,
def kareciz(self, xy: tuple, width: float, height: float, *args, z: float = 0, **kwargs):
kare = Rectangle(xy, width, height, args, kwargs) #5 positional arguments: Matplotlib: working (-3.7.3), not working (3.8.0)
self.main_ax.add_patch(kare)
return kare
TypeError: Rectangle.init() takes 4 positional arguments but 5 were given
def kareciz(self, xy: tuple, width: float, height: float, *args, z: float = 0, **kwargs):
kare = Rectangle(xy, width, height, **kwargs) #4 positional arguments: working (3.8.0) but positions and shapes are incorrect.
self.main_ax.add_patch(kare)
return kare
Is this due to 3.8? Is there a solution that can be done just in the code here?
def kareciz(self, xy: tuple, width, height, angle=0, *args, z: float = 0, **kwargs):
kare = Rectangle(xy, width, height, angle=angle, **kwargs) # When there is no angle, position and shape information is corrupted.
self.main_ax.add_patch(kare)
return kare
I received a warning for the first time in version 3.8.0rc1. After many attempts, my incorrect outputs were corrected when I typed the angle data explicitly (position and shape information was incorrect). Normally it should have given a warning, but I didn’t see it.
It sounds like args contains a single positional value in your call to kareciz(). So Rectangle(xy, width, height, *args, **kwargs) passes 4
positional arguments to Rectangle(), which in turn passes 5 (self, xy, width, height and the value fom args) to Rectangle.__init__.
def _draw_rectangle(self, xy: tuple, width: float, height: float, angle: float=0.0, rotation_point='xy', *, z: float = 0, **kwargs):
#SyntaxError: * argument may appear only once
#TypeError: Template2D._draw_rectangle() takes 4 positional arguments but 5 positional arguments (and 1 keyword-only argument) were given
#AttributeError: Rectangle.set() got an unexpected keyword argument 'z'
rect = Rectangle(xy, width, height, angle=angle, rotation_point=rotation_point, **kwargs)
# Without angle, position and shape information is corrupted: class matplotlib.patches.Rectangle(xy, width, height, *, angle=0.0, rotation_point='xy', **kwargs)
#https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Rectangle.html
self.main_ax.add_patch(rect)
return rect
It works for me in this order too (without * or *args or both, as long as there is an angle, but since * is preferred for new codes, it would make more sense to use *). But it doesn’t work without z because it calls it somewhere else. It works correctly with or without rotation.