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 5368336

Browse filesBrowse files
Made code in ticker.py PEP8 compliant
1 parent 02f0a11 commit 5368336
Copy full SHA for 5368336

File tree

Expand file treeCollapse file tree

1 file changed

+70
-86
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+70
-86
lines changed

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+70-86Lines changed: 70 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ def __call__(self, x, pos=None):
377377
return self.pprint_val(x, d)
378378

379379
def pprint_val(self, x, d):
380-
#if the number is not too big and it's an int, format it as an
381-
#int
380+
# if the number is not too big and it's an int, format it as an
381+
# int
382382
if abs(x) < 1e4 and x == int(x):
383383
return '%d' % x
384384

@@ -395,7 +395,7 @@ def pprint_val(self, x, d):
395395
else:
396396
fmt = '%1.3f'
397397
s = fmt % x
398-
#print d, x, fmt, s
398+
# print d, x, fmt, s
399399
tup = s.split('e')
400400
if len(tup) == 2:
401401
mantissa = tup[0].rstrip('0').rstrip('.')
@@ -417,10 +417,7 @@ class ScalarFormatter(Formatter):
417417
axes.formatter.limits rc parameter.
418418
419419
"""
420-
mode = {'offset' :0,
421-
'scaling' :1,
422-
'none' :2,
423-
}
420+
mode = {'offset': 0, 'scaling': 1, 'none': 2, }
424421
_currentMode = 2
425422

426423
def __init__(self, useOffset=None, useMathText=None, useLocale=None):
@@ -430,9 +427,9 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
430427

431428
self.set_useOffset(False)
432429
self.set_useScalingFactor(False)
433-
if rcParams['axes.formatter.useoffset'] == True:
434-
self._currentMode=self.mode['offset']
435-
self._currentMode=self.mode['none']
430+
if rcParams['axes.formatter.useoffset'] is True:
431+
self._currentMode = self.mode['offset']
432+
self._currentMode = self.mode['none']
436433

437434
self._usetex = rcParams['text.usetex']
438435
if useMathText is None:
@@ -450,73 +447,73 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
450447
def get_useScalingFactor(self):
451448
return self._currentMode == self.mode['scaling']
452449

453-
def set_useScalingFactor(self,val):
450+
def set_useScalingFactor(self, val):
454451
"""
455-
Control and set the scaling factor. Disabling this returns the
452+
Control and set the scaling factor. Disabling this returns the
456453
formatter to its default behavior, e.g. it will try to find
457454
an appropriate scaling/offset if enabled.
458-
Note that either offset or scaling can be used. Therefore,
455+
Note that either offset or scaling can be used. Therefore,
459456
this automatically turns off offset
460457
461458
Parameters
462459
----------
463460
val : (True|False|numeric)
464461
Enable, disable, or sets and enables the use of scaling factor
465-
in the axis.
462+
in the axis.
466463
467464
Returns
468465
-------
469466
NONE
470467
"""
471468

472469
if val in [True, False]:
473-
self.orderOfMagnitude=math.log10(1)
474-
self._currentMode=self.mode['scaling']
475-
if val == False:
476-
self._currentMode=self.mode['none']
477-
elif isinstance(val,numbers.Number):
478-
self._currentMode=self.mode['scaling']
479-
self.orderOfMagnitude=.5*math.log10(val*val)
470+
self.orderOfMagnitude = math.log10(1)
471+
self._currentMode = self.mode['scaling']
472+
if val is False:
473+
self._currentMode = self.mode['none']
474+
elif isinstance(val, numbers.Number):
475+
self._currentMode = self.mode['scaling']
476+
self.orderOfMagnitude = .5*math.log10(val*val)
480477
else:
481478
raise ValueError("'val' must be a number or a boolean")
482479

483-
useScalingFactor = property(fget=get_useScalingFactor, fset=set_useScalingFactor)
480+
useScalingFactor = property(fget=get_useScalingFactor,
481+
fset=set_useScalingFactor)
484482

485483
def get_useOffset(self):
486484
return self._currentMode == self.mode['offset']
487485

488486
def set_useOffset(self, val):
489487
"""
490-
Control and set the offset. Disabling this returns the
488+
Control and set the offset. Disabling this returns the
491489
formatter to its default behavior, e.g. it will try to find
492490
an appropriate scaling/offset if enabled.
493-
Note that either offset or scaling can be used. Therefore,
491+
Note that either offset or scaling can be used. Therefore,
494492
this automatically turns off scaling
495493
496494
Parameters
497495
----------
498496
val : (True|False|numeric)
499497
Enable, disable, or sets and enables the use of an offset
500-
in the axis.
498+
in the axis.
501499
502500
Returns
503501
-------
504502
NONE
505503
"""
506504
if val in [True, False]:
507505
self.offsetval = 0
508-
self._currentMode=self.mode['offset']
509-
if val == False:
510-
self._currentMode=self.mode['none']
511-
elif isinstance(val,numbers.Number):
512-
self._currentMode=self.mode['offset']
506+
self._currentMode = self.mode['offset']
507+
if val is False:
508+
self._currentMode = self.mode['none']
509+
elif isinstance(val, numbers.Number):
510+
self._currentMode = self.mode['offset']
513511
self.offsetval = val
514512
else:
515513
raise ValueError("'val' must be a number or a boolean")
516514

517515
useOffset = property(fget=get_useOffset, fset=set_useOffset)
518516

519-
520517
def get_useLocale(self):
521518
return self._useLocale
522519

@@ -545,13 +542,13 @@ def __call__(self, x, pos=None):
545542

546543
def set_scientific(self, b):
547544
"""
548-
Enable/disable scientific notation
545+
Enable/disable scientific notation
549546
see also :meth:`set_powerlimits`
550547
551548
Parameters
552549
----------
553550
b : (True|False)
554-
Enable, disable scientific notation
551+
Enable, disable scientific notation
555552
556553
Returns
557554
-------
@@ -597,12 +594,11 @@ def format_data(self, value):
597594
s = self._formatSciNotation(s)
598595
return self.fix_minus(s)
599596

600-
601-
def set_offset_string(self,s):
597+
def set_offset_string(self, value):
602598
"""
603599
Set the string which typically contains the offset
604-
or the scaling factor which is to be displayed on the axis.
605-
Set this to None to allow the string set by offset or scaling
600+
or the scaling factor which is to be displayed on the axis.
601+
Set this to None to allow the string set by offset or scaling
606602
algorithm.
607603
608604
Parameters
@@ -613,13 +609,13 @@ def set_offset_string(self,s):
613609
-------
614610
None
615611
"""
616-
self._offsetString=s
612+
self._offsetString = value
617613

618614
def get_offset(self):
619615
"""
620616
Returns a string with the offset(or scientific notation)/scaling
621617
factor which is properly formatted. This is used as additional text
622-
next to the ticks, either determined by offset/scaling or set by the
618+
next to the ticks, either determined by offset/scaling or set by the
623619
user
624620
625621
Parameters
@@ -630,29 +626,30 @@ def get_offset(self):
630626
-------
631627
:string
632628
"""
633-
#String has been set manually, so just return that
634-
if self._offsetString != None :
629+
# String has been set manually, so just return that
630+
if self._offsetString is not None:
635631
return self._offsetString
636632

637633
if len(self.locs) == 0:
638634
return ''
639635
s = ''
640636
offsetStr = ''
641637
sciNotStr = ''
642-
if self._currentMode == self.mode['offset']:
638+
if self._currentMode == self.mode['offset']:
643639
if self._currentMode == self.mode['offset']:
644640
offsetStr = self.format_data(self.offsetval)
645641
if self.offsetval > 0:
646642
offsetStr = ' +' + offsetStr
647-
elif self._currentMode == self.mode['scaling']:
643+
elif self._currentMode == self.mode['scaling']:
648644
if self.orderOfMagnitude:
649645
if self._usetex or self._useMathText:
650646
sciNotStr = self.format_data(10 ** self.orderOfMagnitude)
651647
else:
652-
#sciNotStr = '%g' % 10 **self.orderOfMagnitude
653-
sciNotStr = '\u22C5 ' + self.format_data(10 ** self.orderOfMagnitude)
648+
# sciNotStr = '%g' % 10 **self.orderOfMagnitude
649+
sciNotStr = ('\u22C5 ' + self.format_data(
650+
10 ** self.orderOfMagnitude))
654651

655-
#Do final formatting
652+
# Do final formatting
656653
if self._useMathText:
657654
if sciNotStr != '':
658655
sciNotStr = r'\times%s' % _mathdefault(sciNotStr)
@@ -679,10 +676,10 @@ def set_locs(self, locs):
679676
self._set_format(vmin, vmax)
680677

681678
def _set_offset(self, range):
682-
#Determine if an offset is needed and if so, set it.
683-
#This is only needed when scaling/offset hasn't been set by the user
679+
# Determine if an offset is needed and if so, set it.
680+
# This is only needed when scaling/offset hasn't been set by the user
684681
if self._currentMode != self.mode['none']:
685-
return
682+
return
686683

687684
# offset of 20,001 is 20,000, for example
688685
locs = self.locs
@@ -707,13 +704,12 @@ def _set_offset(self, range):
707704
else:
708705
self.set_useOffset(False)
709706

710-
711707
def _set_orderOfMagnitude(self, range):
712708
# If the user has set scale/offset, their input is used
713709
# if scientific notation is to be used, find the appropriate exponent
714710
# if using an numerical offset, find the exponent after applying the
715-
if self._currentMode != self.mode['none'] or self._scientific == False:
716-
#User specified or unwanted
711+
if self._currentMode != self.mode['none'] or self._scientific is False:
712+
# User specified or unwanted
717713
return
718714

719715
locs = np.absolute(self.locs)
@@ -730,10 +726,10 @@ def _set_orderOfMagnitude(self, range):
730726
oom = math.floor(math.log10(val))
731727
if oom <= self._powerlimits[0]:
732728
self.orderOfMagnitude = oom
733-
self._currentMode=self.mode['scaling']
729+
self._currentMode = self.mode['scaling']
734730
elif oom >= self._powerlimits[1]:
735731
self.orderOfMagnitude = oom
736-
self._currentMode=self.mode['scaling']
732+
self._currentMode = self.mode['scaling']
737733
else:
738734
self.orderOfMagnitude = 0
739735

@@ -744,7 +740,8 @@ def _set_format(self, vmin, vmax):
744740
_locs = list(self.locs) + [vmin, vmax]
745741
else:
746742
_locs = self.locs
747-
locs = (np.asarray(_locs) - self.offsetval) / 10. ** self.orderOfMagnitude
743+
locs = ((np.asarray(_locs) - self.offsetval) /
744+
10. ** self.orderOfMagnitude)
748745
loc_range = np.ptp(locs)
749746
# Curvilinear coordinates can yield two identical points.
750747
if loc_range == 0:
@@ -773,8 +770,8 @@ def _set_format(self, vmin, vmax):
773770
self.format = '$%s$' % _mathdefault(self.format)
774771

775772
def pprint_val(self, x):
776-
#Decide if we are doing offset, scale, or none
777-
if self._currentMode == self.mode['offset'] :
773+
# Decide if we are doing offset, scale, or none
774+
if self._currentMode == self.mode['offset']:
778775
xp = x - self.offsetval
779776
elif self._currentMode == self.mode['scaling']:
780777
xp = x / (10. ** self.orderOfMagnitude)
@@ -877,8 +874,8 @@ def format_data_short(self, value):
877874
return '%-12g' % value
878875

879876
def pprint_val(self, x, d):
880-
#if the number is not too big and it's an int, format it as an
881-
#int
877+
# if the number is not too big and it's an int, format it as an
878+
# int
882879
if abs(x) < 1e4 and x == int(x):
883880
return '%d' % x
884881

@@ -1025,25 +1022,10 @@ class EngFormatter(Formatter):
10251022
# (https://github.com/jcrocholl/pep8/issues/271)
10261023

10271024
# The SI engineering prefixes
1028-
ENG_PREFIXES = {
1029-
-24: "y",
1030-
-21: "z",
1031-
-18: "a",
1032-
-15: "f",
1033-
-12: "p",
1034-
-9: "n",
1035-
-6: "\u03bc",
1036-
-3: "m",
1037-
0: "",
1038-
3: "k",
1039-
6: "M",
1040-
9: "G",
1041-
12: "T",
1042-
15: "P",
1043-
18: "E",
1044-
21: "Z",
1045-
24: "Y"
1046-
}
1025+
ENG_PREFIXES = {-24: "y", -21: "z", -18: "a", -15: "f",
1026+
-12: "p", -9: "n", -6: "\u03bc", -3: "m",
1027+
0: "", 3: "k", 6: "M", 9: "G", 12: "T",
1028+
15: "P", 18: "E", 21: "Z", 24: "Y"}
10471029

10481030
def __init__(self, unit="", places=None):
10491031
self.unit = unit
@@ -1398,15 +1380,15 @@ def le(self, x):
13981380
'return the largest multiple of base <= x'
13991381
d, m = divmod(x, self._base)
14001382
if closeto(m / self._base, 1): # was closeto(m, self._base)
1401-
#looks like floating point error
1383+
# looks like floating point error
14021384
return (d + 1) * self._base
14031385
return d * self._base
14041386

14051387
def gt(self, x):
14061388
'return the smallest multiple of base > x'
14071389
d, m = divmod(x, self._base)
14081390
if closeto(m / self._base, 1):
1409-
#looks like floating point error
1391+
# looks like floating point error
14101392
return (d + 2) * self._base
14111393
return (d + 1) * self._base
14121394

@@ -1605,8 +1587,9 @@ def __call__(self):
16051587
return self.tick_values(vmin, vmax)
16061588

16071589
def tick_values(self, vmin, vmax):
1608-
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=1e-13,
1609-
tiny=1e-14)
1590+
vmin, vmax = mtransforms.nonsingular(vmin,
1591+
vmax, expander=1e-13,
1592+
tiny=1e-14)
16101593
locs = self.bin_boundaries(vmin, vmax)
16111594
prune = self._prune
16121595
if prune == 'lower':
@@ -1624,8 +1607,9 @@ def view_limits(self, dmin, dmax):
16241607
dmin = -maxabs
16251608
dmax = maxabs
16261609

1627-
dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander=1e-12,
1628-
tiny=1.e-13)
1610+
dmin, dmax = mtransforms.nonsingular(dmin,
1611+
dmax, expander=1e-12,
1612+
tiny=1.e-13)
16291613

16301614
if rcParams['axes.autolimit_mode'] == 'round_numbers':
16311615
return np.take(self.bin_boundaries(dmin, dmax), [0, -1])
@@ -2180,8 +2164,8 @@ def get_locator(self, d):
21802164
fld = math.floor(ld)
21812165
base = 10 ** fld
21822166

2183-
#if ld==fld: base = 10**(fld-1)
2184-
#else: base = 10**fld
2167+
# if ld==fld: base = 10**(fld-1)
2168+
# else: base = 10**fld
21852169

21862170
if d >= 5 * base:
21872171
ticksize = base

0 commit comments

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