Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2646527

Browse filesBrowse files
committed
{,test_}ticker.py: small simplifications
1 parent eb56caa commit 2646527
Copy full SHA for 2646527

File tree

2 files changed

+8
-20
lines changed
Filter options

2 files changed

+8
-20
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,11 +1626,10 @@ def test_engformatter_offset_oom(
16261626
):
16271627
UNIT = "eV"
16281628
# Doesn't really matter here, but should be of order of magnitude ~= 1
1629-
r = range(-5, 7)
16301629
fig, ax = plt.subplots()
16311630
# Use some random ugly number
16321631
data_offset = 2.7149*10**oom_center
1633-
ydata = data_offset + np.array(r, dtype=float)*10**oom_noise
1632+
ydata = data_offset + np.arange(-5, 7, dtype=float)*10**oom_noise
16341633
ax.plot(ydata)
16351634
formatter = mticker.EngFormatter(useOffset=True, unit=UNIT)
16361635
# So that offset strings will always have the same size
@@ -1664,10 +1663,7 @@ def test_engformatter_offset_oom(
16641663
for tick in ticks_got:
16651664
# 0 is zero on all orders of magnitudes, no matter what is
16661665
# oom_noise_desired
1667-
if tick[0] == "0":
1668-
prefix_idx = 0
1669-
else:
1670-
prefix_idx = oom_noise_desired
1666+
prefix_idx = 0 if tick[0] == "0" else oom_noise_desired
16711667
assert tick.endswith(formatter.ENG_PREFIXES[prefix_idx] + UNIT)
16721668

16731669

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+6-14Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,7 @@ def get_usetex(self):
468468
return self._usetex
469469

470470
def set_usetex(self, val):
471-
if val is None:
472-
self._usetex = mpl.rcParams['text.usetex']
473-
else:
474-
self._usetex = val
471+
self._usetex = mpl._val_or_rc(val, 'text.usetex')
475472

476473
usetex = property(fget=get_usetex, fset=set_usetex)
477474

@@ -1445,7 +1442,7 @@ def __call__(self, x, pos=None):
14451442
def set_locs(self, locs):
14461443
# docstring inherited
14471444
self.locs = locs
1448-
if len(self.locs) > 0:
1445+
if self.locs:
14491446
vmin, vmax = sorted(self.axis.get_view_interval())
14501447
if self._useOffset:
14511448
self._compute_offset()
@@ -1472,19 +1469,14 @@ def get_offset(self):
14721469
if len(self.locs) == 0:
14731470
return ''
14741471
if self.offset:
1475-
offsetStr = ''
1476-
if self.offset:
1477-
offsetStr = self.format_data(self.offset)
1478-
if self.offset > 0:
1479-
offsetStr = '+' + offsetStr
1472+
offsetStr = self.format_data(self.offset)
1473+
if self.offset > 0:
1474+
offsetStr = '+' + offsetStr
14801475
sciNotStr = self.format_data(10 ** self.orderOfMagnitude)
14811476
if self._useMathText or self._usetex:
14821477
if sciNotStr != '':
14831478
sciNotStr = r'\times%s' % sciNotStr
1484-
s = fr'${sciNotStr}{offsetStr}$'
1485-
else:
1486-
s = ''.join((sciNotStr, offsetStr))
1487-
return self.fix_minus(s)
1479+
return self.fix_minus(f'${sciNotStr}{offsetStr}$')
14881480
return ''
14891481

14901482
def format_eng(self, num):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.