def figaspect(arg):
 isarray = (hasattr(arg, u'shape') and (not np.isscalar(arg)))
 figsize_min = np.array((4.0, 2.0))
 figsize_max = np.array((16.0, 16.0))
 if isarray:
  (nr, nc) = arg.shape[:2]
  arr_ratio = (float(nr) / nc)
 else:
  arr_ratio = float(arg)
 fig_height = rcParams[u'figure.figsize'][1]
 newsize = np.array(((fig_height / arr_ratio), fig_height))
 newsize /= min(1.0, *(newsize / figsize_min))
 newsize /= max(1.0, *(newsize / figsize_max))
 newsize = np.clip(newsize, figsize_min, figsize_max)
 return newsize

def figaspect ( arg ) : isarray = ( hasattr ( arg , u'shape' ) and ( not np . isscalar ( arg ) ) ) figsize_min = np . array ( ( 4.0 , 2.0 ) ) figsize_max = np . array ( ( 16.0 , 16.0 ) ) if isarray : ( nr , nc ) = arg . shape [ : 2 ] arr_ratio = ( float ( nr ) / nc ) else : arr_ratio = float ( arg ) fig_height = rcParams [ u'figure.figsize' ] [ 1 ] newsize = np . array ( ( ( fig_height / arr_ratio ) , fig_height ) ) newsize /= min ( 1.0 , * ( newsize / figsize_min ) ) newsize /= max ( 1.0 , * ( newsize / figsize_max ) ) newsize = np . clip ( newsize , figsize_min , figsize_max ) return newsize
create a figure with specified aspect ratio .