<s> """<STR_LIT>""" <EOL> from __future__ import division , unicode_literals <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib import scale as mscale <EOL> from matplotlib import transforms as mtransforms <EOL> from matplotlib . ticker import NullLocator , FixedLocator <EOL> from matplotlib . ticker import ScalarFormatter , NullFormatter <EOL> from acoustics . bands import octave , third <EOL> class OctaveBandScale ( mscale . ScaleBase ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , axis , ** kwargs ) : <EOL> mscale . ScaleBase . __init__ ( self ) <EOL> def get_transform ( self ) : <EOL> return self . BandTransform ( ) <EOL> def set_default_locators_and_formatters ( self , axis ) : <EOL> axis . set_major_locator ( FixedLocator ( octave ( <NUM_LIT:16> , <NUM_LIT> ) ) ) <EOL> axis . set_major_formatter ( ScalarFormatter ( ) ) <EOL> axis . set_minor_locator ( NullLocator ( ) ) <EOL> axis . set_minor_formatter ( NullFormatter ( ) ) <EOL> def limit_range_for_scale ( self , vmin , vmax , minpos ) : <EOL> return vmin , vmax <EOL> class BandTransform ( mtransforms . Transform ) : <EOL> input_dims = <NUM_LIT:1> <EOL> output_dims = <NUM_LIT:1> <EOL> is_separable = True <EOL> has_inverse = False <EOL> def __init__ ( self ) : <EOL> mtransforms . Transform . __init__ ( self ) <EOL> def transform_non_affine ( self , a ) : <EOL> return np . log10 ( a + <NUM_LIT:1> ) <EOL> mscale . register_scale ( OctaveBandScale ) <EOL> class ThirdBandScale ( mscale . ScaleBase ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , axis , ** kwargs ) : <EOL> mscale . ScaleBase . __init__ ( self ) <EOL> def get_transform ( self ) : <EOL> return self . BandTransform ( ) <EOL> def set_default_locators_and_formatters ( self , axis ) : <EOL> axis . set_major_locator ( NullLocator ( ) ) <EOL> axis . set_major_formatter ( ScalarFormatter ( ) ) <EOL> axis . set_minor_locator ( FixedLocator ( third ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> axis . set_minor_formatter ( ScalarFormatter ( ) ) <EOL> def limit_range_for_scale ( self , vmin , vmax , minpos ) : <EOL> return vmin , vmax <EOL> class BandTransform ( mtransforms . Transform ) : <EOL> input_dims = <NUM_LIT:1> <EOL> output_dims = <NUM_LIT:1> <EOL> is_separable = True <EOL> has_inverse = False <EOL> def __init__ ( self ) : <EOL> mtransforms . Transform . __init__ ( self ) <EOL> def transform_non_affine ( self , a ) : <EOL> return np . log10 ( a + <NUM_LIT:1> ) <EOL> mscale . register_scale ( ThirdBandScale ) <EOL> def plot_octave ( data , octaves , axes = None , kHz = False , xlabel = None , ylabel = None , <EOL> title = None , separator = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> band_type = '<STR_LIT>' <EOL> k_ticks = kHz <EOL> return ( plot_bands ( data , octaves , axes , band_type , k_ticks , xlabel , ylabel , <EOL> title , separator , * args , ** kwargs ) ) <EOL> def plot_third ( data , thirds , axes = None , kHz = False , xlabel = None , ylabel = None , <EOL> title = None , separator = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> band_type = '<STR_LIT>' <EOL> k_ticks = kHz <EOL> return ( plot_bands ( data , thirds , axes , band_type , k_ticks , xlabel , ylabel , <EOL> title , separator , * args , ** kwargs ) ) <EOL> def plot_bands ( data , bands , axes , band_type , k_ticks = False , xlabel = None , <EOL> ylabel = None , title = None , separator = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if axes is None : <EOL> axes = plt . gca ( ) <EOL> factor = <NUM_LIT:0.1> <EOL> min_auto = bands [ <NUM_LIT:0> ] * ( <NUM_LIT:1> - factor ) <EOL> max_auto = bands [ - <NUM_LIT:1> ] * ( <NUM_LIT:1> + factor ) <EOL> axes . set_xlim ( [ min_auto , max_auto ] ) <EOL> axes . set_xscale ( band_type ) <EOL> ticklabels = _get_ticklabels ( band_type , k_ticks , separator ) <EOL> if band_type == '<STR_LIT>' : <EOL> third_ticks = True <EOL> elif band_type == '<STR_LIT>' : <EOL> third_ticks = False <EOL> axes . set_xticklabels ( ticklabels , minor = third_ticks ) <EOL> if xlabel is not None : <EOL> axes . set_xlabel ( xlabel ) <EOL> if ylabel is not None : <EOL> axes . set_ylabel ( ylabel ) <EOL> if title is not None : <EOL> axes . set_title ( title ) <EOL> return axes . plot ( bands , data , * args , ** kwargs ) <EOL> TICKS_OCTAVE = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> """<STR_LIT>""" <EOL> TICKS_OCTAVE_KHZ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> """<STR_LIT>""" <EOL> TICKS_THIRD_OCTAVE = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:100>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> """<STR_LIT>""" <EOL> TICKS_THIRD_OCTAVE_KHZ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:100>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> """<STR_LIT>""" <EOL> def _get_ticklabels ( band_type , kHz , separator ) : <EOL> """<STR_LIT>""" <EOL> if separator is None : <EOL> import locale <EOL> separator = locale . localeconv ( ) [ '<STR_LIT>' ] <EOL> if band_type == '<STR_LIT>' : <EOL> if kHz is True : <EOL> ticklabels = TICKS_OCTAVE_KHZ <EOL> else : <EOL> ticklabels = TICKS_OCTAVE <EOL> else : <EOL> if kHz is True : <EOL> ticklabels = TICKS_THIRD_OCTAVE_KHZ <EOL> else : <EOL> ticklabels = TICKS_THIRD_OCTAVE <EOL> ticklabels = _set_separator ( ticklabels , separator ) <EOL> return ticklabels <EOL> def _set_separator ( ticklabels , separator ) : <EOL> """<STR_LIT>""" <EOL> if separator == '<STR_LIT:.>' : <EOL> bands_sep = ticklabels <EOL> else : <EOL> bands_sep = [ ] <EOL> for item in ticklabels : <EOL> decimal_number_format = item . replace ( '<STR_LIT:.>' , separator ) <EOL> bands_sep . append ( decimal_number_format ) <EOL> return bands_sep </s>
