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

Skip to content

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
merged 6 commits into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DOC Cleaning up mplot3d/wire3d* examples: comments/docstrings, tweaks…
…, and refactoring. [MEP12]
  • Loading branch information
TrishGillett committed Oct 16, 2016
commit 3243b51f10d619e245ded55975e461ec313eb899
31 changes: 19 additions & 12 deletions examples/mplot3d/wire3d_animation_demo.py
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)
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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:

In examples/mplot3d/wire3d_animation_demo.py
#6690 (comment):

+# Set the z axis limits so they aren't recalculated each frame.
+ax.set_zlim(-1, 1)

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.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/matplotlib/matplotlib/pull/6690/files/6a5def2d4d237346f47e4e9da592f05058b1a9f9#r69580992,
or mute the thread
https://github.com/notifications/unsubscribe/AARy-L05A6cqDxNM8ebAlLR7HrjuixW9ks5qSnTcgaJpZM4JE0ZQ
.

Copy link
Contributor Author

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?

Copy link
Member

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.


# 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)))
10 changes: 9 additions & 1 deletion examples/mplot3d/wire3d_demo.py
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()
18 changes: 15 additions & 3 deletions examples/mplot3d/wire3d_zero_stride.py
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()