8000 DOC explicitely add 3D axis to figure to be compatible with future matplotlib by moshekaplan · Pull Request #21916 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC explicitely add 3D axis to figure to be compatible with future matplotlib #21916

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

Closed
wants to merge 1 commit into from

Conversation

moshekaplan
Copy link

Reference Issues/PRs

N/A

What does this implement/fix? Explain your changes.

Fixes deprecation warnings in plot_cluster_iris.py.

https://scikit-learn.org/stable/auto_examples/cluster/plot_cluster_iris.html currently displays the following deprecation warning:
plot_cluster_iris.py:48: MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. 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. This is consistent with other Axes classes.

Any other comments?

It may be worth reviewing other pages to see where else this issue is present.

Fixes deprecation warnings in plot_cluster_iris.py.

https://scikit-learn.org/stable/auto_examples/cluster/plot
8000
_cluster_iris.html currently displays the following deprecation warning:
`plot_cluster_iris.py:48: MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. 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.  This is consistent with other Axes classes.`
@ogrisel
Copy link
Member
ogrisel commented Dec 8, 2021

Unfortunately this breaks the doc-min-dependencies build:

https://app.circleci.com/pipelines/github/scikit-learn/scikit-learn/20971/workflows/d1105c44-b6a4-4bcb-8c9b-434a4a82c738/jobs/166226

Traceback (most recent call last):
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/sphinx_gallery/gen_gallery.py", line 159, in call_memory
    return 0., func()
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/sphinx_gallery/gen_rst.py", line 466, in __call__
    exec(self.code, self.fake_main.__dict__)
  File "/home/circleci/project/examples/cluster/plot_cluster_iris.py", line 48, in <module>
    ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134, auto_add_to_figure=False)
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 104, in __init__
    *args, **kwargs)
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 541, in __init__
    self.update(kwargs)
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/matplotlib/artist.py", line 888, in update
    for k, v in props.items()]
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/matplotlib/artist.py", line 888, in <listcomp>
    for k, v in props.items()]
  File "/home/circleci/miniconda/envs/testenv/lib/python3.7/site-packages/matplotlib/artist.py", line 881, in _update_property
    raise AttributeError('Unknown property %s' % k)
AttributeError: Unknown property auto_add_to_figure

I am not sure how to best deal with the fact that we want our doc to also build on older scipy versions...

Maybe it would be possible to write a small helper function in the example to deal with backward compat depending on the scipy version? This will render the example a bit verbose but it's probably better than a warning.

Copy link
Member
@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can remove the auto_add_to_figure parameter. We will be warned for some time but we will not need to change the code from matplotlib 3.6

@@ -45,7 +45,8 @@
titles = ["8 clusters", "3 clusters", "3 clusters, bad initialization"]
for name, est in estimators:
fig = plt.figure(fignum, figsize=(4, 3))
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134)
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134, auto_add_to_figure=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134, auto_add_to_figure=False)
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134)

@@ -63,7 +64,8 @@

# Plot the ground truth
fig = plt.figure(fignum, figsize=(4, 3))
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134)
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134, auto_add_to_figure=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134, auto_add_to_figure=False)
ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134)

@glemaitre glemaitre changed the title examples: plot_cluster_iris.py: Fix warnings DOC explicitely add 3D axis to figure to be compatible with future matplotlib Jan 28, 2022
@cmarmo
Copy link
Contributor
cmarmo commented Apr 12, 2022

The DeprecationWarning has been fixed in #22594. Thanks for your work @moshekaplan .

@cmarmo cmarmo closed this Apr 12, 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.

4 participants
0