<s> from __future__ import division <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> import matplotlib . ticker as mticker <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def figure ( aspect_ratio = <NUM_LIT> , scale = <NUM_LIT:1> , width = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> size = figaspect ( aspect_ratio , scale = scale , width = width ) <EOL> return plt . figure ( figsize = size , ** kwargs ) <EOL> def figaspect ( aspect_ratio = <NUM_LIT> , scale = <NUM_LIT:1> , width = None ) : <EOL> """<STR_LIT>""" <EOL> if width is None : <EOL> width , h = plt . rcParams [ '<STR_LIT>' ] <EOL> height = width * aspect_ratio <EOL> return width * scale , height * scale <EOL> def clear_frame ( ax = None ) : <EOL> """<STR_LIT>""" <EOL> ax = ax if ax is not None else plt . gca ( ) <EOL> ax . xaxis . set_ticks ( [ ] ) <EOL> ax . yaxis . set_ticks ( [ ] ) <EOL> for spine in ax . spines . values ( ) : <EOL> spine . set_visible ( False ) <EOL> def figimage ( img , scale = <NUM_LIT:1> , dpi = None ) : <EOL> """<STR_LIT>""" <EOL> dpi = dpi if dpi is not None else plt . rcParams [ '<STR_LIT>' ] <EOL> h , w = img . shape <EOL> figsize = np . array ( ( w , h ) , dtype = float ) / dpi * scale <EOL> fig , ax = plt . subplots ( figsize = figsize , dpi = dpi ) <EOL> fig . subplots_adjust ( left = <NUM_LIT:0> , bottom = <NUM_LIT:0> , right = <NUM_LIT:1> , top = <NUM_LIT:1> ) <EOL> ax . set_axis_off ( ) <EOL> ax . imshow ( img ) <EOL> ax . autoscale ( enable = False ) <EOL> return fig , ax <EOL> def clip_zero_formatter ( tick_val , tick_pos ) : <EOL> """<STR_LIT>""" <EOL> if tick_val == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> return tick_val <EOL> def cross_spines ( zero_cross = False , remove_zeros = True , ax = None ) : <EOL> """<STR_LIT>""" <EOL> ax = ax if ax is not None else plt . gca ( ) <EOL> ax . spines [ '<STR_LIT:right>' ] . set_visible ( False ) <EOL> ax . spines [ '<STR_LIT>' ] . set_visible ( False ) <EOL> ax . xaxis . set_ticks_position ( '<STR_LIT>' ) <EOL> ax . yaxis . set_ticks_position ( '<STR_LIT:left>' ) <EOL> if zero_cross : <EOL> ax . spines [ '<STR_LIT>' ] . set_position ( '<STR_LIT>' ) <EOL> ax . spines [ '<STR_LIT:left>' ] . set_position ( '<STR_LIT>' ) <EOL> if remove_zeros : <EOL> formatter = mticker . FuncFormatter ( clip_zero_formatter ) <EOL> ax . xaxis . set_major_formatter ( formatter ) <EOL> ax . yaxis . set_major_formatter ( formatter ) <EOL> return ax <EOL> def pad_limits ( pad_frac = <NUM_LIT> , ax = None ) : <EOL> """<STR_LIT>""" <EOL> ax = ax if ax is not None else plt . gca ( ) <EOL> ax . set_xlim ( _calc_limits ( ax . xaxis , pad_frac ) ) <EOL> ax . set_ylim ( _calc_limits ( ax . yaxis , pad_frac ) ) <EOL> def _calc_limits ( axis , frac ) : <EOL> limits = axis . get_data_interval ( ) <EOL> if axis . get_scale ( ) == '<STR_LIT>' : <EOL> log_limits = np . log10 ( limits ) <EOL> mag = np . diff ( log_limits ) [ <NUM_LIT:0> ] <EOL> pad = np . array ( [ - mag * frac , mag * frac ] ) <EOL> return <NUM_LIT:10> ** ( log_limits + pad ) <EOL> elif axis . get_scale ( ) == '<STR_LIT>' : <EOL> mag = np . diff ( limits ) [ <NUM_LIT:0> ] <EOL> pad = np . array ( [ - mag * frac , mag * frac ] ) <EOL> return limits + pad <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from yutils . mpl . core import demo_plot <EOL> f , ax = plt . subplots ( ) <EOL> demo_plot ( ax ) <EOL> cross_spines ( ax ) <EOL> ax . set_title ( '<STR_LIT>' ) <EOL> f , ax = plt . subplots ( ) <EOL> demo_plot ( ax ) <EOL> pad_limits ( ax = ax ) <EOL> ax . set_title ( '<STR_LIT>' ) <EOL> plt . show ( ) </s>
