-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Tidying up and tweaking mplot3d examples [MEP12] #6690
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
efiring
merged 6 commits into
matplotlib:master
from
TrishGillett:mplot3d-examples-MEP12-b
Oct 16, 2016
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
885a82b
DOC Change ax.set_xlim3d to ax.set_xlim, etc.
TrishGillett 890e880
DOC Cleaning up mplot3d examples quiver3d_demo, rotate_axes3d_demo, s…
TrishGillett 13bb609
DOC Cleaning up mplot3d/surface3d* examples: comments/docstrings, twe…
TrishGillett 3243b51
DOC Cleaning up mplot3d/wire3d* examples: comments/docstrings, tweaks…
TrishGillett bfbf0ca
DOC Cleaning up mplot3d/tri* examples: comments/docstrings, tweaks, a…
TrishGillett d47dcce
Add example titles in sphinx-gallery style.
TrishGillett 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
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
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
''' | ||
================== | ||
Rotating a 3D plot | ||
================== | ||
|
||
A very simple animation of a rotating 3D plot. | ||
|
||
See wire3d_animation_demo for another simple example of animating a 3D plot. | ||
''' | ||
|
||
from mpl_toolkits.mplot3d import axes3d | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
# load some test data for demonstration and plot a wireframe | ||
X, Y, Z = axes3d.get_test_data(0.1) | ||
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5) | ||
|
||
# rotate the axes and update | ||
for angle in range(0, 360): | ||
ax.view_init(30, angle) | ||
plt.draw() | ||
plt.pause(.001) | ||
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
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
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 |
---|---|---|
@@ -1,23 +1,42 @@ | ||
''' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A title on that PR could be "3D surfaces" |
||
====================== | ||
3D surface (color map) | ||
====================== | ||
|
||
Demonstrates plotting a 3D surface colored with the coolwarm color map. | ||
The surface is made opaque by using antialiased=False. | ||
|
||
Also demonstrates using the LinearLocator and custom formatting for the | ||
z axis tick labels. | ||
''' | ||
|
||
from mpl_toolkits.mplot3d import Axes3D | ||
import matplotlib.pyplot as plt | ||
from matplotlib import cm | ||
from matplotlib.ticker import LinearLocator, FormatStrFormatter | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
fig = plt.figure() | ||
ax = fig.gca(projection='3d') | ||
|
||
# Make data. | ||
X = np.arange(-5, 5, 0.25) | ||
Y = np.arange(-5, 5, 0.25) | ||
X, Y = np.meshgrid(X, Y) | ||
R = np.sqrt(X**2 + Y**2) | ||
Z = np.sin(R) | ||
|
||
# Plot the surface. | ||
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, | ||
linewidth=0, antialiased=False) | ||
ax.set_zlim(-1.01, 1.01) | ||
|
||
# Customize the z axis. | ||
ax.set_zlim(-1.01, 1.01) | ||
ax.zaxis.set_major_locator(LinearLocator(10)) | ||
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f')) | ||
|
||
# Add a color bar which maps values to colors. | ||
fig.colorbar(surf, shrink=0.5, aspect=5) | ||
|
||
plt.show() |
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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
''' | ||
======================== | ||
3D surface (solid color) | ||
======================== | ||
|
||
Demonstrates a very basic plot of a 3D surface using a solid color. | ||
''' | ||
|
||
from mpl_toolkits.mplot3d import Axes3D | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
# Make data | ||
u = np.linspace(0, 2 * np.pi, 100) | ||
v = np.linspace(0, np.pi, 100) | ||
|
||
x = 10 * np.outer(np.cos(u), np.sin(v)) | ||
y = 10 * np.outer(np.sin(u), np.sin(v)) | ||
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) | ||
|
||
# Plot the surface | ||
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') | ||
|
||
plt.show() |
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
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 |
---|---|---|
@@ -1,26 +1,39 @@ | ||
# By Armin Moser | ||
''' | ||
================================= | ||
3D surface with polar coordinates | ||
================================= | ||
|
||
Demonstrates plotting a surface defined in polar coordinates. | ||
Uses the reversed version of the YlGnBu color map. | ||
Also demonstrates writing axis labels with latex math mode. | ||
|
||
Example contributed by Armin Moser. | ||
''' | ||
|
||
from mpl_toolkits.mplot3d import Axes3D | ||
import matplotlib | ||
import numpy as np | ||
from matplotlib import cm | ||
from matplotlib import pyplot as plt | ||
step = 0.04 | ||
maxval = 1.0 | ||
import numpy as np | ||
|
||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
# create supporting points in polar coordinates | ||
# Create the mesh in polar coordinates and compute corresponding Z. | ||
r = np.linspace(0, 1.25, 50) | ||
p = np.linspace(0, 2*np.pi, 50) | ||
R, P = np.meshgrid(r, p) | ||
# transform them to cartesian system | ||
Z = ((R**2 - 1)**2) | ||
|
||
# Express the mesh in the cartesian system. | ||
X, Y = R*np.cos(P), R*np.sin(P) | ||
|
||
Z = ((R**2 - 1)**2) | ||
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r) | ||
ax.set_zlim3d(0, 1) | ||
# Plot the surface. | ||
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.YlGnBu_r) | ||
|
||
# Tweak the limits and add latex math labels. | ||
ax.set_zlim(0, 1) | ||
ax.set_xlabel(r'$\phi_\mathrm{real}$') | ||
ax.set_ylabel(r'$\phi_\mathrm{im}$') | ||
ax.set_zlabel(r'$V(\phi)$') | ||
|
||
plt.show() |
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
Oops, something went wrong.
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.
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.
On my computer, this line was needed to make the example viewable. I got the idea for it when I did the wire3d_animation_demo example, but I'm not sure this is the correct practice since in both examples this line seems to trigger a deprecation warning:
Let me know if there's something else I should do with this instead.
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.
Which backend are you using?
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.
Dumb question: how do I tell?
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.
import matplotlib; print(matplotlib.get_backend())
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.
Thanks! Qt4Agg.
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.
If I'm going to make an issue for this, which part is the issue? That nothing displays for me without the use of plt.pause(), or that the use of plt.pause() triggers that warning? I'm not really clear on whether plt.draw() is supposed to be sufficient in an example like this.
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.
This may be because
plt.draw
is now lazy and won't draw until idle?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.
@QuLogic You are correct.
plt.pause()
spins the GUI event loop so the update gets processed.I don't think we need to worry about the warning in this PR, it is a know issue.