Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: The Axes3D does not work as expected. #24639

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
jerryliu20d opened this issue Dec 6, 2022 · 3 comments · Fixed by #24715
Closed

[Bug]: The Axes3D does not work as expected. #24639

jerryliu20d opened this issue Dec 6, 2022 · 3 comments · Fixed by #24715
Labels
Milestone

Comments

@jerryliu20d
Copy link

Bug summary

The Axes3D does not work as expected.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D


plt.style.use('_mpl-gallery')

# Make data
np.random.seed(19680801)
n = 100
rng = np.random.default_rng()
xs = rng.uniform(23, 32, n)
ys = rng.uniform(0, 100, n)
zs = rng.uniform(-50, -25, n)

# Plot
# fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(xs, ys, zs)

ax.set(xticklabels=[],
       yticklabels=[],
       zticklabels=[])

plt.show()

Actual outcome

The outcome figure is blank.

Expected outcome

Should show figure with correct content.

Additional information

The code works well if changed to
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

Operating system

Windows

Matplotlib Version

3.6.2

Matplotlib Backend

Qt5Agg

Python version

3.9.15

Jupyter version

NA

Installation

conda

@jerryliu20d jerryliu20d changed the title [Bug]: [Bug]: The Axes3D does not work as expected. Dec 6, 2022
@timhoffm
Copy link
Member

timhoffm commented Dec 6, 2022

Axes objects need correct wiring up with the figure. Therefore, you never instantiate any Axes directly, but use the Axes creation methods on Figure (or pyplot), which do that logic for you.I think this is consistently shown throughout our documentation. Have you found a place that suggests otherwise?

Todo: Maybe we should add a note to Axes constructors that they are not intended for the end-user.

@timhoffm timhoffm added Documentation Community support Users in need of help. labels Dec 6, 2022
@oscargus
Copy link
Member

oscargus commented Dec 6, 2022

There is a note here: https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html

"Changed in version 1.0.0: Prior to Matplotlib 1.0.0, only a single Axes3D could be created per figure; it needed to be directly instantiated as ax = Axes3D(fig)."

This can possibly be dropped now? But also it indicates that there are old examples out there using this.

(Some tests use ax = fig.add_axes(Axes3D(fig)) so that is, I guess, the way to do it if one really wants to instantiate it separately, but not the way to go.)

@tacaswell
Copy link
Member

Between this issue and #24725 what is happening that this came up 2x in a week or so but not for the last 4 months from when 3.6 came out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants