-
-
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 1 commit
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
DOC Cleaning up mplot3d/wire3d* examples: comments/docstrings, tweaks…
…, and refactoring. [MEP12]
- Loading branch information
commit 3243b51f10d619e245ded55975e461ec313eb899
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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
from __future__ import print_function | ||
""" | ||
A very simple 'animation' of a 3D plot | ||
A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
from mpl_toolkits.mplot3d import axes3d | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import time | ||
|
||
|
||
def generate(X, Y, phi): | ||
''' | ||
Generates Z data for the points in the X, Y meshgrid and parameter phi. | ||
''' | ||
R = 1 - np.sqrt(X**2 + Y**2) | ||
return np.cos(2 * np.pi * X + phi) * R | ||
|
||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
# Make the X, Y meshgrid. | ||
xs = np.linspace(-1, 1, 50) | ||
ys = np.linspace(-1, 1, 50) | ||
X, Y = np.meshgrid(xs, ys) | ||
Z = generate(X, Y, 0.0) | ||
|
||
# Set the z axis limits so they aren't recalculated each frame. | ||
ax.set_zlim(-1, 1) | ||
|
||
# Begin plotting. | ||
wframe = None | ||
tstart = time.time() | ||
for phi in np.linspace(0, 360 / 2 / np.pi, 100): | ||
|
||
oldcol = wframe | ||
for phi in np.linspace(0, 180. / np.pi, 100): | ||
# If a line collection is already remove it before drawing. | ||
if wframe: | ||
ax.collections.remove(wframe) | ||
|
||
# Plot the new wireframe and pause briefly before continuing. | ||
Z = generate(X, Y, phi) | ||
wframe = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2) | ||
|
||
# Remove old line collection before drawing | ||
if oldcol is not None: | ||
ax.collections.remove(oldcol) | ||
|
||
plt.pause(.001) | ||
|
||
print('FPS: %f' % (100 / (time.time() - tstart))) | ||
print('Average FPS: %f' % (100 / (time.time() - tstart))) |
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,10 +1,18 @@ | ||
''' | ||
A very basic demonstration of a wireframe 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') | ||
|
||
# Grab some test data. | ||
X, Y, Z = axes3d.get_test_data(0.05) | ||
|
||
# Plot a basic wireframe. | ||
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) | ||
|
||
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,12 +1,24 @@ | ||
''' | ||
Demonstrates that setting rstride or cstride to 0 causes wires to not be | ||
generated in the corresponding direction. | ||
''' | ||
|
||
from mpl_toolkits.mplot3d import axes3d | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(8, 12), subplot_kw={'projection': '3d'}) | ||
|
||
# Get the test data | ||
X, Y, Z = axes3d.get_test_data(0.05) | ||
|
||
# Give the first plot only wireframes of the type y = c | ||
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=0) | ||
ax1.set_title("Column stride 0") | ||
ax1.set_title("Column (x) stride set to 0") | ||
|
||
# Give the second plot only wireframes of the type x = c | ||
ax2.plot_wireframe(X, Y, Z, rstride=0, cstride=10) | ||
ax2.set_title("Row stride 0") | ||
ax2.set_title("Row (y) stride set to 0") | ||
|
||
plt.tight_layout() | ||
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.
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.
The z axis scale was changing as the rotation progressed, so this seemed like a nice addition.
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.
That shouldn't happen. Makes me wonder if it is a bug with the style changes for 2.0.
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'm doing a git bisect to try and nail down when this happened.
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.
Using this example as a test script, I see the same behaviour with versions 1.5.2, 1.5.1, 1.5.0, 1.4.0, 1.2.0, and 1.0.0. I haven't found a commit where this behaviour doesn't happen.
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.
ok, how about this issue and the other one with regards to "plt.pause()"
get filed as issues? Let's take out those two changes for now and keep it
focused on just MEP12. We'll have to investigate those two issues further
to see if there is something deeper going on.
On Tue, Jul 5, 2016 at 11:14 AM, Trish Gillett-Kawamoto <
[email protected]> wrote:
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'm just realizing I was thinking of the rotate_axes3d example when I wrote the note saying the z limits changed 'as the rotation progressed'. Sorry for that confusion. In fact it's the data that's changing in this example, not the rotation. As the largest z value contracts from say 1 to 0.6, the z limits are self-adjusting so that the extremes of the surface are always using the full z range. In that updated context, would you say that the behaviour is as expected or does something still sound fishy?
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.
@TrishGillett That behavior is expected given how this code works.