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

Skip to content

Deprecate proj3d.mod. #13020

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 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,10 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
mag = half * (mag / half + 0.5).astype(int)

num_flags = np.floor(mag / flag).astype(int)
mag = np.mod(mag, flag)
mag = mag % flag

num_barb = np.floor(mag / full).astype(int)
mag = np.mod(mag, full)
mag = mag % full

half_flag = mag >= half
empty_flag = ~(half_flag | (num_flags > 0) | (num_barb > 0))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/triinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def compute_geom_weights(self):
alpha2 = np.arctan2(p2[:, 1]-p0[:, 1], p2[:, 0]-p0[:, 0])
# In the below formula we could take modulo 2. but
# modulo 1. is safer regarding round-off errors (flat triangles).
angle = np.abs(np.mod((alpha2-alpha1) / np.pi, 1.))
angle = np.abs(((alpha2-alpha1) / np.pi) % 1)
# Weight proportional to angle up np.pi/2; null weight for
# degenerated cases 0 and np.pi (note that `angle` is normalized
# by np.pi).
Expand Down
8 changes: 4 additions & 4 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def get_proj(self):

self.eye = E
self.vvec = R - E
self.vvec = self.vvec / proj3d._mod(self.vvec)
self.vvec = self.vvec / np.linalg.norm(self.vvec)

if abs(relev) > np.pi/2:
# upside down
Expand Down Expand Up @@ -1762,9 +1762,9 @@ def _shade_colors(self, color, normals, lightsource=None):
# chosen for backwards-compatibility
lightsource = LightSource(azdeg=225, altdeg=19.4712)

shade = np.array([np.dot(n / proj3d._mod(n), lightsource.direction)
if proj3d._mod(n) else np.nan
for n in normals])
with np.errstate(invalid="ignore"):
shade = ((normals / np.linalg.norm(normals, axis=1, keepdims=True))
@ lightsource.direction)
Copy link
Member

Choose a reason for hiding this comment

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

OK, I couldn't even google this one. What does the @ operator do?

Copy link
Member

Choose a reason for hiding this comment

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

That‘s a new operator introduced in python 3. Numpy uses it for matrix multiplication. a @ b is the same as np.dot(a, b), just more readable.

mask = ~np.isnan(shade)

if mask.any():
Expand Down
20 changes: 7 additions & 13 deletions lib/mpl_toolkits/mplot3d/proj3d.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# 3dproj.py
#
"""
Various transforms used for by the 3D code
"""

import numpy as np
import numpy.linalg as linalg

Expand Down Expand Up @@ -79,15 +78,10 @@ def line2d_seg_dist(p1, p2, p0):
return _line2d_seg_dist(p1, p2, p0)


def _mod(v):
"""3d vector length"""
return np.sqrt(v[0]**2+v[1]**2+v[2]**2)


@cbook.deprecated("3.1")
@cbook.deprecated("3.1", alternative="np.linalg.norm")
def mod(v):
"""3d vector length"""
return _mod(v)
return np.sqrt(v[0]**2+v[1]**2+v[2]**2)


def world_transformation(xmin, xmax,
Expand All @@ -103,9 +97,9 @@ def world_transformation(xmin, xmax,
def view_transformation(E, R, V):
n = (E - R)
## new
# n /= mod(n)
# n /= np.linalg.norm(n)
# u = np.cross(V,n)
# u /= mod(u)
# u /= np.linalg.norm(u)
# v = np.cross(n,u)
# Mr = np.diag([1.]*4)
# Mt = np.diag([1.]*4)
Expand All @@ -114,9 +108,9 @@ def view_transformation(E, R, V):
## end new

## old
n = n / _mod(n)
n = n / np.linalg.norm(n)
u = np.cross(V, n)
u = u / _mod(u)
u = u / np.linalg.norm(u)
v = np.cross(n, u)
Mr = [[u[0], u[1], u[2], 0],
[v[0], v[1], v[2], 0],
Expand Down