-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
Conversation
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.`
Unfortunately this breaks the 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. |
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
The |
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.