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

Skip to content

DOC: Add more 3D plot types #28243

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

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions galleries/plot_types/3D/bar3d_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
==========================
bar3d(x, y, z, dx, dy, dz)
==========================

See `~mpl_toolkits.mplot3d.axes3d.Axes3D.bar3d`.
"""
import matplotlib.pyplot as plt
import numpy as np

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

# Make data
x = [1, 1, 2, 2]
y = [1, 2, 1, 2]
z = [0, 0, 0, 0]
dx = np.ones_like(x)*0.5
dy = np.ones_like(x)*0.5
dz = [2, 3, 1, 4]

# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.bar3d(x, y, z, dx, dy, dz)

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

plt.show()
27 changes: 27 additions & 0 deletions galleries/plot_types/3D/plot3d_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
================
plot(xs, ys, zs)
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
plot(xs, ys, zs)
plot(x, y, z)

For consistency. Best also change the variable names below.

oh, I see, the existing scatter() was using this convention, but that's really the odd ball and should be changed as well.

Copy link
Contributor Author

@scottshambaugh scottshambaugh May 17, 2024

Choose a reason for hiding this comment

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

The Axes3D.plot function has xs, ys, and zs as the argument names, I figure it's best to be consistent with that?
https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.plot.html#mpl_toolkits.mplot3d.axes3d.Axes3D.plot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add it to the list of annoying API inconsistencies

================

See `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot`.
"""
import matplotlib.pyplot as plt
import numpy as np

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

# Make data
n = 100
xs = np.linspace(0, 1, n)
ys = np.sin(xs * 6 * np.pi)
zs = np.cos(xs * 6 * np.pi)

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

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

plt.show()
32 changes: 32 additions & 0 deletions galleries/plot_types/3D/quiver3d_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
========================
quiver(X, Y, Z, U, V, W)
========================

See `~mpl_toolkits.mplot3d.axes3d.Axes3D.quiver`.
"""
import matplotlib.pyplot as plt
import numpy as np

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

# Make data
n = 4
x = np.linspace(-1, 1, n)
y = np.linspace(-1, 1, n)
z = np.linspace(-1, 1, n)
X, Y, Z = np.meshgrid(x, y, z)
U = (X + Y)/5
V = (Y - X)/5
W = Z*0


# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.quiver(X, Y, Z, U, V, W)

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

plt.show()
27 changes: 27 additions & 0 deletions galleries/plot_types/3D/stem3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
=============
stem(x, y, z)
=============

See `~mpl_toolkits.mplot3d.axes3d.Axes3D.stem`.
"""
import matplotlib.pyplot as plt
import numpy as np

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

# Make data
n = 20
x = np.sin(np.linspace(0, 2*np.pi, n))
y = np.cos(np.linspace(0, 2*np.pi, n))
z = np.linspace(0, 1, n)

# Plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.stem(x, y, z)

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

plt.show()
Loading