77"""
88import math
99from fractions import Fraction
10+ from typing import Optional
1011
1112from matplotlib .ticker import Formatter , Locator , MaxNLocator
1213
@@ -24,15 +25,15 @@ class FactorLocator(Locator):
2425
2526 Parameters
2627 ----------
27- factor : float
28+ factor : float, default: 1.0
2829 The factor to extract.
29- nbins : int
30+ nbins : int, optional
3031 Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
3132 **kwargs
3233 Additional arguments passed to :class:`~matplotlib.tickers.MaxNLocator`.
3334 """
3435
35- def __init__ (self , factor = 1.0 , nbins = None , ** kwargs ):
36+ def __init__ (self , factor : float = 1.0 , nbins : Optional [ int ] = None , ** kwargs ):
3637 """
3738 Locator for finding multiples of *factor*.
3839 """
@@ -65,18 +66,18 @@ class PiLocator(FactorLocator):
6566
6667 Parameters
6768 ----------
68- nbins : int
69+ nbins : int, optional
6970 Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
7071 """
7172
72- def __init__ (self , nbins = None , ** kwargs ):
73+ def __init__ (self , nbins : Optional [ int ] = None , ** kwargs ):
7374 super ().__init__ (factor = math .pi , nbins = nbins , ** kwargs )
7475
7576
7677class SampleFrequencyLocator (FactorLocator ):
7778 """Locator for finding multiples of sample frequency."""
7879
79- def __init__ (self , nbins = None , fs = 1.0 , ** kwargs ):
80+ def __init__ (self , nbins : Optional [ int ] = None , fs : float = 1.0 , ** kwargs ):
8081 super ().__init__ (factor = fs / (2 * math .pi ), nbins = nbins , ** kwargs )
8182
8283
@@ -86,11 +87,11 @@ class DegreeLocator(MaxNLocator):
8687
8788 Parameters
8889 ----------
89- nbins : int
90+ nbins : int, optional
9091 Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
9192 """
9293
93- def __init__ (self , nbins = None , ** kwargs ):
94+ def __init__ (self , nbins : Optional [ int ] = None , ** kwargs ):
9495 steps = kwargs .pop ('steps' , [1 , 1.5 , 2 , 3 , 5 , 6 , 10 ])
9596 if nbins is None :
9697 nbins = 'auto'
@@ -121,7 +122,12 @@ class FactorFormatter(Formatter):
121122 locs = []
122123
123124 def __init__ (
124- self , digits = 3 , factor = 1.0 , name = "constant" , name_on_all_numbers = False , ** kwargs
125+ self ,
126+ digits : int = 3 ,
127+ factor : float = 1.0 ,
128+ name : str = "constant" ,
129+ name_on_all_numbers : bool = False ,
130+ ** kwargs ,
125131 ):
126132 self ._digits = digits
127133 self ._factor = factor
@@ -164,7 +170,7 @@ class PiFormatter(FactorFormatter):
164170 Cannot include *factor* and *name*.
165171 """
166172
167- def __init__ (self , digits = 3 , ** kwargs ):
173+ def __init__ (self , digits : int = 3 , ** kwargs ):
168174 super ().__init__ (digits = digits , factor = math .pi , name = r"\pi" , ** kwargs )
169175
170176
@@ -183,7 +189,7 @@ class SampleFrequencyFormatter(FactorFormatter):
183189 Cannot include *factor* and *name*.
184190 """
185191
186- def __init__ (self , digits = 3 , fs = 1.0 , ** kwargs ):
192+ def __init__ (self , digits : int = 3 , fs : float = 1.0 , ** kwargs ):
187193 super ().__init__ (
188194 digits = digits , factor = fs / (2 * math .pi ), name = r"f_s" , ** kwargs
189195 )
@@ -204,7 +210,7 @@ class DegreeFormatter(FactorFormatter):
204210 Cannot include *factor*, *name*, and *only_name_when_one*.
205211 """
206212
207- def __init__ (self , digits = 3 , ** kwargs ):
213+ def __init__ (self , digits : int = 3 , ** kwargs ):
208214 super ().__init__ (
209215 digits = digits ,
210216 factor = 1 ,
@@ -233,7 +239,7 @@ class PiRationalFormatter(Formatter):
233239 # individual ones
234240 locs = []
235241
236- def __init__ (self , digits = 3 , pi_always_in_numerator = True , ** kwargs ):
242+ def __init__ (self , digits : int = 3 , pi_always_in_numerator : bool = True , ** kwargs ):
237243 self ._digits = digits
238244 self ._pi_always_in_numerator = pi_always_in_numerator
239245 super ().__init__ (** kwargs )
0 commit comments