11import numpy
22from matplotlib import pyplot
33
4- from . import dist
5- from . import utils
4+ from paramnormal import dist , utils
65
76
87def _check_distro (distro , ** params ):
98 # check if we're returning the class definition or an instance
10- as_class = params .pop (' as_class' , False )
11- if hasattr (distro , ' pdf' ):
9+ as_class = params .pop (" as_class" , False )
10+ if hasattr (distro , " pdf" ):
1211 return distro
13- elif hasattr (distro , ' from_params' ):
12+ elif hasattr (distro , " from_params" ):
1413 return _check_distro (distro .name , as_class = as_class , ** params )
1514 else :
1615 try :
1716 distro = getattr (dist , distro )
18- except :
19- raise ValueError ("{ } is not a valid paramnormal distribution". format ( distro ) )
17+ except ( AttributeError , TypeError ) :
18+ raise ValueError (f" { distro } is not a valid paramnormal distribution" )
2019
2120 _params = utils ._remove_nones (** params )
2221 if as_class :
@@ -74,7 +73,7 @@ def random(distro, **params):
7473
7574 """
7675
77- shape = params .pop (' shape' , None )
76+ shape = params .pop (" shape" , None )
7877 distro = _check_distro (distro , ** params )
7978 return distro .rvs (size = shape )
8079
@@ -121,8 +120,17 @@ def fit(distro, data, as_params=True, **guesses):
121120 return distro .from_params (params )
122121
123122
124- def plot (distro , which = 'PDF' , data = None , fit_dist = True , ax = None ,
125- pad = 0.05 , xscale = 'linear' , line_opts = None , ** guesses ):
123+ def plot (
124+ distro ,
125+ which = "PDF" ,
126+ data = None ,
127+ fit_dist = True ,
128+ ax = None ,
129+ pad = 0.05 ,
130+ xscale = "linear" ,
131+ line_opts = None ,
132+ ** guesses ,
133+ ):
126134 """
127135 Plot the PDF of a dataset and other representations of the
128136 distribution (histogram, kernel density estimate, and rug plot).
@@ -248,11 +256,11 @@ def plot(distro, which='PDF', data=None, fit_dist=True, ax=None,
248256 fxn = getattr (distro , which .lower ())
249257
250258 # determine and set the xlimits of the plot
251- xlimits = distro .ppf ([pad / 100 , 1 - pad / 100 ])
259+ xlimits = distro .ppf ([pad / 100 , 1 - pad / 100 ])
252260
253261 # determine the x-values
254- if xscale == ' log' :
255- #xlimits = numpy.log10(xlimits)
262+ if xscale == " log" :
263+ # xlimits = numpy.log10(xlimits)
256264 x_hat = numpy .logspace (* numpy .log10 (xlimits ), num = 100 )
257265 else :
258266 x_hat = numpy .linspace (* xlimits , num = 100 )
@@ -261,9 +269,9 @@ def plot(distro, which='PDF', data=None, fit_dist=True, ax=None,
261269 y_hat = fxn (x_hat )
262270
263271 line_opts = dict () if line_opts is None else line_opts
264- line_opts [' label' ] = line_opts .pop (' label' , which )
272+ line_opts [" label" ] = line_opts .pop (" label" , which )
265273
266- line , = ax .plot (x_hat , y_hat , ** line_opts )
274+ ( line ,) = ax .plot (x_hat , y_hat , ** line_opts )
267275 ax .set_xscale (xscale )
268276
269277 return ax
0 commit comments