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

Skip to content

Commit 160d9f5

Browse files
authored
Merge pull request #11532 from Harnesser/examples-fix-radian-display
Fix the display of negative radian values in `basic_units.py`
2 parents 5c32712 + a894b95 commit 160d9f5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

examples/units/basic_units.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,21 @@ def __call__(self, operation, units):
297297

298298
# radians formatting
299299
def rad_fn(x, pos=None):
300-
n = int((x / np.pi) * 2.0 + 0.25)
300+
if x >= 0:
301+
n = int((x / np.pi) * 2.0 + 0.25)
302+
else:
303+
n = int((x / np.pi) * 2.0 - 0.25)
304+
301305
if n == 0:
302306
return '0'
303307
elif n == 1:
304308
return r'$\pi/2$'
305309
elif n == 2:
306310
return r'$\pi$'
311+
elif n == -1:
312+
return r'$-\pi/2$'
313+
elif n == -2:
314+
return r'$-\pi$'
307315
elif n % 2 == 0:
308316
return r'$%s\pi$' % (n//2,)
309317
else:

0 commit comments

Comments
 (0)