10000 Backport PR #11532: Fix the display of negative radian values in `bas… · matplotlib/matplotlib@40311a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40311a3

Browse files
dstansbyMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #11532: Fix the display of negative radian values in basic_units.py
1 parent b56734e commit 40311a3

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
@@ -298,13 +298,21 @@ def __call__(self, operation, units):
298298

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

0 commit comments

Comments
 (0)
0