-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Create box3d example #19363
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
Create box3d example #19363
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ba38757
Create box3d.py
iuryt 8852be6
Update box3d.py
iuryt cb35724
Update box3d.py
iuryt 76024ea
Update box3d.py
iuryt 0eb24d9
Update box3d.py
iuryt 719e698
Update box3d.py
iuryt 1b982e9
NumPy instead of Xarray
iuryt 03537f1
Update box3d.py
iuryt 3dd17cc
Update box3d.py
iuryt e4b80fd
Update examples/mplot3d/box3d.py
iuryt adeaa0d
Update examples/mplot3d/box3d.py
iuryt 34a4e98
Update examples/mplot3d/box3d.py
iuryt 1d6984e
Update examples/mplot3d/box3d.py
iuryt 1c6f970
Update examples/mplot3d/box3d.py
iuryt 3db0dd0
Update box3d.py
iuryt 24017e4
Update box3d.py
iuryt 68597ec
Update examples/mplot3d/box3d.py
iuryt cf67e4f
Remove '\n' from xlabel and ylabel
iuryt c88ed51
Update box3d.py
iuryt 6f5f355
Update examples/mplot3d/box3d.py
iuryt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
=================== | ||
3D box surface plot | ||
=================== | ||
|
||
Given data on a gridded volume ``X``, ``Y``, ``Z``, this example plots the | ||
data values on the volume surfaces. | ||
|
||
The strategy is to select the data from each surface and plot | ||
contours separately using `.axes3d.Axes3D.contourf` with appropriate | ||
parameters *zdir* and *offset*. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
# Define dimensions | ||
Nx, Ny, Nz = 100, 300, 500 | ||
X, Y, Z = np.meshgrid(np.arange(Nx), np.arange(Ny), -np.arange(Nz)) | ||
|
||
# Create fake data | ||
data = (((X+100)**2 + (Y-20)**2 + 2*Z)/1000+1) | ||
|
||
kw = { | ||
'vmin': data.min(), | ||
'vmax': data.max(), | ||
'levels': np.linspace(data.min(), data.max(), 10), | ||
} | ||
|
||
# Create a figure with 3D ax | ||
fig = plt.figure(figsize=(5, 4)) | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
# Plot contour surfaces | ||
_ = ax.contourf( | ||
X[:, :, 0], Y[:, :, 0], data[:, :, 0], | ||
zdir='z', offset=0, **kw | ||
) | ||
_ = ax.contourf( | ||
X[0, :, :], data[0, :, :], Z[0, :, :], | ||
zdir='y', offset=0, **kw | ||
) | ||
C = ax.contourf( | ||
data[:, -1, :], Y[:, -1, :], Z[:, -1, :], | ||
zdir='x', offset=X.max(), **kw | ||
) | ||
# -- | ||
|
||
|
||
# Set limits of the plot from coord limits | ||
xmin, xmax = X.min(), X.max() | ||
ymin, ymax = Y.min(), Y.max() | ||
zmin, zmax = Z.min(), Z.max() | ||
ax.set(xlim=[xmin, xmax], ylim=[ymin, ymax], zlim=[zmin, zmax]) | ||
|
||
# Plot edges | ||
edges_kw = dict(color='0.4', linewidth=1, zorder=1e3) | ||
ax.plot([xmax, xmax], [ymin, ymax], 0, **edges_kw) | ||
ax.plot([xmin, xmax], [ymin, ymin], 0, **edges_kw) | ||
ax.plot([xmax, xmax], [ymin, ymin], [zmin, zmax], **edges_kw) | ||
|
||
# Set labels and zticks | ||
ax.set( | ||
xlabel='X [km]', | ||
ylabel='Y [km]', | ||
zlabel='Z [m]', | ||
zticks=[0, -150, -300, -450], | ||
) | ||
|
||
# Set distance and angle view | ||
ax.view_init(40, -30) | ||
ax.dist = 11 | ||
|
||
# Colorbar | ||
fig.colorbar(C, ax=ax, fraction=0.02, pad=0.1, label='Name [units]') | ||
|
||
# Show Figure | ||
plt.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.