8000 DOC: get rid of matplotlib DeprecationWarning in plot_cluster_iris.py by nathansquan · Pull Request #22594 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC: get rid of matplotlib DeprecationWarning in plot_cluster_iris.py #22594

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

Conversation

nathansquan
Copy link
Contributor
@nathansquan nathansquan commented Feb 23, 2022

Reference Issues/PRs

part of #22586.

What does this implement/fix? Explain your changes.

Removes the warning message produced by matplotlib in examples/cluster/plot_cluster_iris.py.

The warning states: "Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6."

I added the keyword argument auto_add_to_figure=False and added fig.add_axes(ax) in the line below each use of Axes3D. I believe it should maintain the perspective and size of the plots compared to the solution found in #22547, which uses matplotlib.figure.Figure.add_subplot.

@lesteve
Copy link
Member
lesteve commented Feb 24, 2022

Thanks for your PR, can you follow the recommendations in #22586 to use projection='3d' and use figure_add_subplot(projection='3d')? As you can see in the doc-min-dependencies build, which was also noticed in #22547 (comment) using auto_add_figure does not work for older matplotlib version.

@nathansquan
Copy link
Contributor Author

Ah, sorry about that. I've pushed a new commit with the recommended changes.

@nathansquan
Copy link
Contributor Author

@lesteve I've made some more changes. Could you help me understand why this ci/circleci: doc-min-dependencies is failing? I'm not sure what the cause of this error is: ValueError: Unknown projection '3d'

@lesteve
Copy link
Member
lesteve commented Feb 24, 2022

Apparently you need the Axes3D import to be able to use projection='3d' for older matplotlib versions (not sure which version exactly for our min matplotlib dependencies is amongst them), e.g. see this https://stackoverflow.com/a/56222305

@lesteve
Copy link
Member
lesteve commented Feb 24, 2022

It looks like this is a relatively recent thing: the import is not needed for matplotlib >= 3.2: matplotlib/matplotlib#16192 (comment)

Now you have a linting error, because you are importing something and you are not using it, can you do something like this:

# unused but required import for doing 3d projections with matplotlib < 3.2
import mpl_toolkits.mplot3d  # noqa: F401

@lesteve
Copy link
Member
lesteve commented Feb 24, 2022

I gave you the wrong error code to ignore indeed 🙄 ...

@nathansquan
Copy link
Contributor Author

No worries. This is my first PR so thank you for your patience and help. Please let me know if there's any additional tasks I need to do for this PR

@lesteve
Copy link
Member
lesteve commented Feb 24, 2022

Looks good to me, merging, thanks a lot!

@lesteve lesteve changed the title Issue22586.examples.cluster.plot cluster iris DOC: get rid of matplotlib DeprecationWarning in plot_cluster_iris.py Feb 24, 2022
@lesteve lesteve merged commit a1a5588 into scikit-learn:main Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0