-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Cannot Create lines.AxLine #27503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you want to construct these objects directly, you can explicitly pass
However, the usual way to create these objects is through the axline method which does have the relevant defaults. Do you have a use-case that requires constructing the |
@rcomer Would any changes in lines.AxLine() solve this issue? Let me know if I can work on it if it needs to be done. |
The idea use case is I'd like to not only draw a line on a chart with AxLine, but I wanted to update it as part of a loop, as part of an animation or a live plot. However, since So, I can just pass one of the arguments as 'None' and that will work. Maybe |
It does look like the documentation for |
OK, so we can close this? |
We maybe we should also add a note to the |
This is not the most elegant API. If I would design this now, I‘d make one of the variants a factory class method, but migrating is not worth it and better documentation should be enough. |
Bug summary
It is impossible to create a new
Matplotlib.lines.AxLine
artist because the constructor cannot be satisfiedCode for reproduction
Actual outcome
first attempt:
TypeError: AxLine.__init__() missing 1 required positional argument: 'slope'
second attempt:
TypeError: AxLine.__init__() missing 1 required positional argument: 'xy2'
third attempt:
TypeError: Exactly one of 'xy2' and 'slope' must be given
Expected outcome
The first and second attempt should create and return AxLine objects. Only the third attempt should raise an exception
Additional information
The constructor for AxLine does not provide default values for either 'xy2' or 'slope', which makes both required, resulting in the errors in attempts 1 and 2.
Suggested fix:
default both xy2 and slope to
None
.Operating system
No response
Matplotlib Version
3.8.2
Matplotlib Backend
No response
Python version
3.12.1
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: