#NEWLINE# def prep_ticks( ax , index , ax_type , props ) : #NEWLINE# #INDENT# "Prepare axis obj belonging to axes obj.\n\n    positional arguments:\n    ax - the mpl axes instance\n    index - the index of the axis in `props`\n    ax_type - 'x' or 'y' (for now)\n    props - an mplexporter poperties dictionary\n\n    " #NEWLINE# axis_dict = dict ( ) #NEWLINE# if ( ax_type == 'x' ) : #NEWLINE# #INDENT# axis = ax . get_xaxis ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ax_type == 'y' ) : #NEWLINE# #INDENT# axis = ax . get_yaxis ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return dict ( ) #NEWLINE# #UNINDENT# #UNINDENT# scale = props [ 'axes' ] [ index ] [ 'scale' ] #NEWLINE# if ( scale == 'linear' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# tickvalues = props [ 'axes' ] [ index ] [ 'tickvalues' ] #NEWLINE# tick0 = tickvalues [ 0 ] #NEWLINE# dticks = [ round ( ( tickvalues [ i ] - tickvalues [ ( i - 1 ) ] ) , 12 ) for i in range ( 1 , ( len ( tickvalues ) - 1 ) ) ] #NEWLINE# if all ( [ ( dticks [ i ] == dticks [ ( i - 1 ) ] ) for i in range ( 1 , ( len ( dticks ) - 1 ) ) ] ) : #NEWLINE# #INDENT# dtick = ( tickvalues [ 1 ] - tickvalues [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# warnings . warn ( "'linear' {0}-axis tick spacing not even, ignoring mpl tick formatting." . format ( ax_type ) ) #NEWLINE# raise TypeError #NEWLINE# #UNINDENT# #UNINDENT# except ( IndexError , TypeError ) : #NEWLINE# #INDENT# axis_dict [ 'nticks' ] = props [ 'axes' ] [ index ] [ 'nticks' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# axis_dict [ 'tick0' ] = tick0 #NEWLINE# axis_dict [ 'dtick' ] = dtick #NEWLINE# axis_dict [ 'tickmode' ] = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( scale == 'log' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# axis_dict [ 'tick0' ] = props [ 'axes' ] [ index ] [ 'tickvalues' ] [ 0 ] #NEWLINE# axis_dict [ 'dtick' ] = ( props [ 'axes' ] [ index ] [ 'tickvalues' ] [ 1 ] - props [ 'axes' ] [ index ] [ 'tickvalues' ] [ 0 ] ) #NEWLINE# axis_dict [ 'tickmode' ] = False #NEWLINE# #UNINDENT# except ( IndexError , TypeError ) : #NEWLINE# #INDENT# axis_dict = dict ( nticks = props [ 'axes' ] [ index ] [ 'nticks' ] ) #NEWLINE# #UNINDENT# base = axis . get_transform ( ) . base #NEWLINE# if ( base == 10 ) : #NEWLINE# #INDENT# if ( ax_type == 'x' ) : #NEWLINE# #INDENT# axis_dict [ 'range' ] = [ math . log10 ( props [ 'xlim' ] [ 0 ] ) , math . log10 ( props [ 'xlim' ] [ 1 ] ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ax_type == 'y' ) : #NEWLINE# #INDENT# axis_dict [ 'range' ] = [ math . log10 ( props [ 'ylim' ] [ 0 ] ) , math . log10 ( props [ 'ylim' ] [ 1 ] ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# axis_dict = dict ( range = None , type = 'linear' ) #NEWLINE# warnings . warn ( "Converted non-base10 {0}-axis log scale to 'linear'" . format ( ax_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return dict ( ) #NEWLINE# #UNINDENT# #UNINDENT# formatter = axis . get_major_formatter ( ) . __class__ . __name__ #NEWLINE# if ( ( ax_type == 'x' ) and ( 'DateFormatter' in formatter ) ) : #NEWLINE# #INDENT# axis_dict [ 'type' ] = 'date' #NEWLINE# try : #NEWLINE# #INDENT# axis_dict [ 'tick0' ] = mpl_dates_to_datestrings ( axis_dict [ 'tick0' ] , formatter ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# axis_dict . pop ( 'dtick' , None ) #NEWLINE# axis_dict . pop ( 'tickmode' , None ) #NEWLINE# axis_dict [ 'range' ] = mpl_dates_to_datestrings ( props [ 'xlim' ] , formatter ) #NEWLINE# #UNINDENT# #UNINDENT# if ( formatter == 'LogFormatterMathtext' ) : #NEWLINE# #INDENT# axis_dict [ 'exponentformat' ] = 'e' #NEWLINE# #UNINDENT# return axis_dict