Issue
I am using matplotlib.pyplot module imported as plt for plots.
In the plt.plot() statement, if I pass the arguments as "x= array1, "y= array2", I get "TypeError: plot got an unexpected keyword argument 'x' ".
The code gets executed correctly if I simple pass "array1 and array2", without explicitly saying they correspond to x and y axes.
Why is that?
Solution
If you look at the function definition, https://github.com/matplotlib/matplotlib/blob/9a24fb724331f50baf0da4d17188860357d328a9/lib/matplotlib/axes/_axes.py#L72, you can see the asterisk there, and the use of that doesn't work with using keywords for non-optional parameters. See Python args and kwargs: Demystified for example.
def plot(self, *args, scalex=True, scaley=True, data=None, **kwargs):
"""
Plot y versus x as lines and/or markers.
Call signatures::
plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
Answered By - Gijs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.