#NEWLINE# def setupTwoYAxes( self ) : #NEWLINE# #INDENT# Ldata = [ ] #NEWLINE# Rdata = [ ] #NEWLINE# seriesWithMissingValuesL = [ ] #NEWLINE# seriesWithMissingValuesR = [ ] #NEWLINE# self . yLabelsL = [ ] #NEWLINE# self . yLabelsR = [ ] #NEWLINE# Ldata += self . dataLeft #NEWLINE# Rdata += self . dataRight #NEWLINE# seriesWithMissingValuesL = [ series for series in Ldata if ( None in series ) ] #NEWLINE# seriesWithMissingValuesR = [ series for series in Rdata if ( None in series ) ] #NEWLINE# if ( self . params . get ( 'drawNullAsZero' ) and seriesWithMissingValuesL ) : #NEWLINE# #INDENT# yMinValueL = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# yMinValueL = safeMin ( [ safeMin ( series ) for series in Ldata if ( not series . options . get ( 'drawAsInfinite' ) ) ] ) #NEWLINE# #UNINDENT# if ( self . params . get ( 'drawNullAsZero' ) and seriesWithMissingValuesR ) : #NEWLINE# #INDENT# yMinValueR = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# yMinValueR = safeMin ( [ safeMin ( series ) for series in Rdata if ( not series . options . get ( 'drawAsInfinite' ) ) ] ) #NEWLINE# #UNINDENT# if ( self . areaMode == 'stacked' ) : #NEWLINE# #INDENT# yMaxValueL = safeSum ( [ safeMax ( series ) for series in Ldata ] ) #NEWLINE# yMaxValueR = safeSum ( [ safeMax ( series ) for series in Rdata ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# yMaxValueL = safeMax ( [ safeMax ( series ) for series in Ldata ] ) #NEWLINE# yMaxValueR = safeMax ( [ safeMax ( series ) for series in Rdata ] ) #NEWLINE# #UNINDENT# if ( yMinValueL is None ) : #NEWLINE# #INDENT# yMinValueL = 0.0 #NEWLINE# #UNINDENT# if ( yMinValueR is None ) : #NEWLINE# #INDENT# yMinValueR = 0.0 #NEWLINE# #UNINDENT# if ( yMaxValueL is None ) : #NEWLINE# #INDENT# yMaxValueL = 1.0 #NEWLINE# #UNINDENT# if ( yMaxValueR is None ) : #NEWLINE# #INDENT# yMaxValueR = 1.0 #NEWLINE# #UNINDENT# if ( 'yMaxLeft' in self . params ) : #NEWLINE# #INDENT# yMaxValueL = self . params [ 'yMaxLeft' ] #NEWLINE# #UNINDENT# if ( 'yMaxRight' in self . params ) : #NEWLINE# #INDENT# yMaxValueR = self . params [ 'yMaxRight' ] #NEWLINE# #UNINDENT# if ( ( 'yLimitLeft' in self . params ) and ( self . params [ 'yLimitLeft' ] < yMaxValueL ) ) : #NEWLINE# #INDENT# yMaxValueL = self . params [ 'yLimitLeft' ] #NEWLINE# #UNINDENT# if ( ( 'yLimitRight' in self . params ) and ( self . params [ 'yLimitRight' ] < yMaxValueR ) ) : #NEWLINE# #INDENT# yMaxValueR = self . params [ 'yLimitRight' ] #NEWLINE# #UNINDENT# if ( 'yMinLeft' in self . params ) : #NEWLINE# #INDENT# yMinValueL = self . params [ 'yMinLeft' ] #NEWLINE# #UNINDENT# if ( 'yMinRight' in self . params ) : #NEWLINE# #INDENT# yMinValueR = self . params [ 'yMinRight' ] #NEWLINE# #UNINDENT# if ( yMaxValueL <= yMinValueL ) : #NEWLINE# #INDENT# yMaxValueL = ( yMinValueL + 1 ) #NEWLINE# #UNINDENT# if ( yMaxValueR <= yMinValueR ) : #NEWLINE# #INDENT# yMaxValueR = ( yMinValueR + 1 ) #NEWLINE# #UNINDENT# yVarianceL = ( yMaxValueL - yMinValueL ) #NEWLINE# yVarianceR = ( yMaxValueR - yMinValueR ) #NEWLINE# orderL = math . log10 ( yVarianceL ) #NEWLINE# orderR = math . log10 ( yVarianceR ) #NEWLINE# orderFactorL = ( 10 ** math . floor ( orderL ) ) #NEWLINE# orderFactorR = ( 10 ** math . floor ( orderR ) ) #NEWLINE# vL = ( yVarianceL / orderFactorL ) #NEWLINE# vR = ( yVarianceR / orderFactorR ) #NEWLINE# yDivisors = str ( self . params . get ( 'yDivisors' , '4,5,6' ) ) #NEWLINE# yDivisors = [ int ( d ) for d in yDivisors . split ( ',' ) ] #NEWLINE# prettyValues = ( 0.1 , 0.2 , 0.25 , 0.5 , 1.0 , 1.2 , 1.25 , 1.5 , 2.0 , 2.25 , 2.5 ) #NEWLINE# divisorInfoL = [ ] #NEWLINE# divisorInfoR = [ ] #NEWLINE# for d in yDivisors : #NEWLINE# #INDENT# qL = ( vL / d ) #NEWLINE# qR = ( vR / d ) #NEWLINE# pL = closest ( qL , prettyValues ) #NEWLINE# pR = closest ( qR , prettyValues ) #NEWLINE# divisorInfoL . append ( ( pL , abs ( ( qL - pL ) ) ) ) #NEWLINE# divisorInfoR . append ( ( pR , abs ( ( qR - pR ) ) ) ) #NEWLINE# #UNINDENT# divisorInfoL . sort ( key = ( lambda i : i [ 1 ] ) ) #NEWLINE# divisorInfoR . sort ( key = ( lambda i : i [ 1 ] ) ) #NEWLINE# prettyValueL = divisorInfoL [ 0 ] [ 0 ] #NEWLINE# prettyValueR = divisorInfoR [ 0 ] [ 0 ] #NEWLINE# self . yStepL = ( prettyValueL * orderFactorL ) #NEWLINE# self . yStepR = ( prettyValueR * orderFactorR ) #NEWLINE# if ( 'yStepLeft' in self . params ) : #NEWLINE# #INDENT# self . yStepL = self . params [ 'yStepLeft' ] #NEWLINE# #UNINDENT# if ( 'yStepRight' in self . params ) : #NEWLINE# #INDENT# self . yStepR = self . params [ 'yStepRight' ] #NEWLINE# #UNINDENT# self . yBottomL = ( self . yStepL * math . floor ( ( yMinValueL / self . yStepL ) ) ) #NEWLINE# self . yBottomR = ( self . yStepR * math . floor ( ( yMinValueR / self . yStepR ) ) ) #NEWLINE# self . yTopL = ( self . yStepL * math . ceil ( ( yMaxValueL / self . yStepL ) ) ) #NEWLINE# self . yTopR = ( self . yStepR * math . ceil ( ( yMaxValueR / self . yStepR ) ) ) #NEWLINE# if ( self . logBase and ( yMinValueL > 0 ) and ( yMinValueR > 0 ) ) : #NEWLINE# #INDENT# self . yBottomL = math . pow ( self . logBase , math . floor ( math . log ( yMinValueL , seriesWithMissingValuesR . logBase ) ) ) #NEWLINE# self . yTopL = math . pow ( self . logBase , math . ceil ( math . log ( yMaxValueL , self . logBase ) ) ) #NEWLINE# self . yBottomR = math . pow ( self . logBase , math . floor ( math . log ( yMinValueR , self . logBase ) ) ) #NEWLINE# self . yTopR = math . pow ( self . logBase , math . ceil ( math . log ( yMaxValueR , self . logBase ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . logBase and ( ( yMinValueL <= 0 ) or ( yMinValueR <= 0 ) ) ) : #NEWLINE# #INDENT# raise GraphError ( 'Logarithmic scale specified with a dataset with a minimum value less than or equal to zero' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'yMaxLeft' in self . params ) : #NEWLINE# #INDENT# self . yTopL = self . params [ 'yMaxLeft' ] #NEWLINE# #UNINDENT# if ( 'yMaxRight' in self . params ) : #NEWLINE# #INDENT# self . yTopR = self . params [ 'yMaxRight' ] #NEWLINE# #UNINDENT# if ( 'yMinLeft' in self . params ) : #NEWLINE# #INDENT# self . yBottomL = self . params [ 'yMinLeft' ] #NEWLINE# #UNINDENT# if ( 'yMinRight' in self . params ) : #NEWLINE# #INDENT# self . yBottomR = self . params [ 'yMinRight' ] #NEWLINE# #UNINDENT# self . ySpanL = ( self . yTopL - self . yBottomL ) #NEWLINE# self . ySpanR = ( self . yTopR - self . yBottomR ) #NEWLINE# if ( self . ySpanL == 0 ) : #NEWLINE# #INDENT# self . yTopL += 1 #NEWLINE# self . ySpanL += 1 #NEWLINE# #UNINDENT# if ( self . ySpanR == 0 ) : #NEWLINE# #INDENT# self . yTopR += 1 #NEWLINE# self . ySpanR += 1 #NEWLINE# #UNINDENT# self . graphHeight = ( self . area [ 'ymax' ] - self . area [ 'ymin' ] ) #NEWLINE# self . yScaleFactorL = ( float ( self . graphHeight ) / float ( self . ySpanL ) ) #NEWLINE# self . yScaleFactorR = ( float ( self . graphHeight ) / float ( self . ySpanR ) ) #NEWLINE# def makeLabel( yValue , yStep = None , ySpan = None ) : #NEWLINE# #INDENT# ( yValue , prefix ) = format_units ( yValue , yStep , system = self . params . get ( 'yUnitSystem' ) ) #NEWLINE# ( ySpan , spanPrefix ) = format_units ( ySpan , yStep , system = self . params . get ( 'yUnitSystem' ) ) #NEWLINE# if ( yValue < 0.1 ) : #NEWLINE# #INDENT# return ( '%g %s' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( yValue < 1.0 ) : #NEWLINE# #INDENT# return ( '%.2f %s' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( ySpan > 10 ) or ( spanPrefix != prefix ) ) : #NEWLINE# #INDENT# if isinstance ( yValue , float ) : #NEWLINE# #INDENT# return ( '%.1f %s ' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%d %s ' % ( int ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ySpan > 3 ) : #NEWLINE# #INDENT# return ( '%.1f %s ' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ySpan > 0.1 ) : #NEWLINE# #INDENT# return ( '%.2f %s ' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%g %s' % ( float ( yValue ) , prefix ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . yLabelValuesL = self . getYLabelValues ( self . yBottomL , self . yTopL , self . yStepL ) #NEWLINE# self . yLabelValuesR = self . getYLabelValues ( self . yBottomR , self . yTopR , self . yStepR ) #NEWLINE# for value in self . yLabelValuesL : #NEWLINE# #INDENT# self . yLabelsL . append ( makeLabel ( value , self . yStepL , self . ySpanL ) ) #NEWLINE# #UNINDENT# for value in self . yLabelValuesR : #NEWLINE# #INDENT# self . yLabelsR . append ( makeLabel ( value , self . yStepR , self . ySpanR ) ) #NEWLINE# #UNINDENT# self . yLabelWidthL = max ( [ self . getExtents ( label ) [ 'width' ] for label in self . yLabelsL ] ) #NEWLINE# self . yLabelWidthR = max ( [ self . getExtents ( label ) [ 'width' ] for label in self . yLabelsR ] ) #NEWLINE# xMin = ( self . margin + ( self . yLabelWidthL * 1.02 ) ) #NEWLINE# if ( self . area [ 'xmin' ] < xMin ) : #NEWLINE# #INDENT# self . area [ 'xmin' ] = xMin #NEWLINE# #UNINDENT# xMax = ( self . width - ( self . yLabelWidthR * 1.02 ) ) #NEWLINE# if ( self . area [ 'xmax' ] >= xMax ) : #NEWLINE# #INDENT# self . area [ 'xmax' ] = xMax