FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Normalization of elevation and azimuth angles for surface plots by jinshifen33 · Pull Request #10762 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .png  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 5 additions & 5 deletions lib/mpl_toolkits/mplot3d/axes3d.py
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
Expand Up @@ -964,16 +964,16 @@ def view_init(self, elev=None, azim=None):
"""

self.dist = 10

# normalize the angle to stay between [-180, 180]
if elev is None:
self.elev = self.initial_elev
self.elev = art3d.norm_angle(self.initial_elev)
else:
self.elev = elev
self.elev = art3d.norm_angle(elev)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If you're going to normalize it at all, elevation should be normalized to [-90, +90]

jinshifen33 Mar 19, 2018 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality


if azim is None:
self.azim = self.initial_azim
self.azim = art3d.norm_angle(self.initial_azim)
else:
self.azim = azim
self.azim = art3d.norm_angle(azim)

def set_proj_type(self, proj_type):
"""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
53 changes: 43 additions & 10 deletions lib/mpl_toolkits/tests/test_mplot3d.py
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
Expand Up @@ -186,6 +186,33 @@ def test_plot_3d_from_2d():
ax.plot(xs, ys, zs=0, zdir='y')


@image_comparison(baseline_images=['surface3d_rotate_gt_270deg'],
remove_text=True, extensions=['png'])
def test_rotate_gt_270deg():
elevation = 345
angle = None

fig = plt.figure()
ax = fig.gca(projection='3d')
# get test data, copied from axes3d.get_test_data(0.05)
# avoiding create too much dependency
x = y = np.arange(-3.0, 3.0, 0.05)
X, Y = np.meshgrid(x, y)

Z1 = np.exp(-(X**2 + Y**2) / 2) / (2 * np.pi)
Z2 = (np.exp(-(((X - 1) / 1.5)**2 + ((Y - 1) / 0.5)**2) / 2) /
(2 * np.pi * 0.5 * 1.5))
Z = Z2 - Z1

X = X * 10
Y = Y * 10
Z = Z * 500
# plot below
s = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, lw=0)
ax.view_init(azim=angle, elev=elevation)
ax.axis('off')


@image_comparison(baseline_images=['surface3d'], remove_text=True)
def test_surface3d():
fig = plt.figure()
Expand Down Expand Up @@ -316,10 +343,11 @@ def test_quiver3d():
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(baseline_images=['quiver3d_empty'], remove_text=True)
def test_quiver3d_empty():
fig = plt.figure()
Expand All @@ -330,10 +358,11 @@ def test_quiver3d_empty():
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(baseline_images=['quiver3d_masked'], remove_text=True)
def test_quiver3d_masked():
fig = plt.figure()
Expand All @@ -346,12 +375,13 @@ def test_quiver3d_masked():
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
np.sin(np.pi * z))
u = np.ma.masked_where((-0.4 < x) & (x < 0.1), u, copy=False)
v = np.ma.masked_where((0.1 < y) & (y < 0.7), v, copy=False)

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)


@image_comparison(baseline_images=['quiver3d_pivot_middle'], remove_text=True,
extensions=['png'])
def test_quiver3d_pivot_middle():
Expand All @@ -363,10 +393,11 @@ def test_quiver3d_pivot_middle():
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='middle', normalize=True)


@image_comparison(baseline_images=['quiver3d_pivot_tail'], remove_text=True,
extensions=['png'])
def test_quiver3d_pivot_tail():
Expand All @@ -378,7 +409,7 @@ def test_quiver3d_pivot_tail():
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail', normalize=True)

Expand Down Expand Up @@ -425,17 +456,18 @@ def test_axes3d_labelpad():
def test_axes3d_cla():
# fixed in pull request 4553
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.set_axis_off()
ax.cla() # make sure the axis displayed is 3D (not 2D)


def test_plotsurface_1d_raises():
x = np.linspace(0.5, 10, num=100)
y = np.linspace(0.5, 10, num=100)
X, Y = np.meshgrid(x, y)
z = np.random.randn(100)

fig = plt.figure(figsize=(14,6))
fig = plt.figure(figsize=(14, 6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
with pytest.raises(ValueError):
ax.plot_surface(X, Y, z)
Expand Down Expand Up @@ -534,6 +566,7 @@ def test_proj_axes_cube_ortho():
ax.set_xlim(-200, 200)
ax.set_ylim(-200, 200)


def test_rot():
V = [1, 0, 0, 1]
rotated_V = proj3d.rot_x(V, np.pi / 6)
Expand Down Expand Up @@ -674,9 +707,9 @@ def test_rgb_data(self):
x, y, z = np.indices((10, 10, 10))
voxels = (x == y) | (y == z)
colors = np.zeros((10, 10, 10, 3))
colors[...,0] = x/9.0
colors[...,1] = y/9.0
colors[...,2] = z/9.0
colors[..., 0] = x/9.0
colors[..., 1] = y/9.0
colors[..., 2] = z/9.0
ax.voxels(voxels, facecolors=colors)

@image_comparison(
Expand Down

Back | FazBrowse Home | New Git URL