(x,mn,mx,w,c=u'X')
return u'[%s]' % (nnc+npc+ppc+pnc)
u'''Draws a simple asciiart bar graph. Very handy for
    visualizing what's going on with the data.
    x= Value from sensor, mn= minimum plottable value,
    mx= maximum plottable value, w= width of plot in chars,
    c= the character to plot with.
u'''Draws a simple asciiart bar graph. Very handy for
    visualizing what's going on with the data.
    x= Value from sensor, mn= minimum plottable value,
    mx= maximum plottable value, w= width of plot in chars,
    c= the character to plot with.
u Draws a simple asciiart bar graph . Very handy for visualizing what s going on with the data . x = Value from sensor mn = minimum plottable value mx = maximum plottable value w = width of plot in chars c = the character to plot with .
def bargraph(x,mn,mx,w,c=u'X'):
    u'''Draws a simple asciiart bar graph. Very handy for
    visualizing what's going on with the data.
    x= Value from sensor, mn= minimum plottable value,
    mx= maximum plottable value, w= width of plot in chars,
    c= the character to plot with.'''
    if not w: return u'' # No width!
    if x<mn: x= mn      # Clip to bounds.
    if x>mx: x= mx      # Clip to bounds.
    tx= mx-mn # Total real units possible to show on graph.
    if tx<=0: return u'backwards' # Stupid bounds.
    upw= tx/float(w) # X Units per output char width.
    if upw<=0: return u'what?' # Don't let this happen.
    negpu, pospu, negnonpu, posnonpu= 0,0,0,0
    if mn < 0: # Then there is a negative part to graph.
        if x < 0: # And the plot is on the negative side.
            negpu= -x + min(0,mx)
            negnonpu= -mn + x
        else: # Plot is on pos. Neg side is empty.
            negnonpu= -mn + min(0,mx) # But still show some empty neg.
    if mx > 0: # There is a positive part to the graph
        if x > 0: # And the plot is on the positive side.
            pospu= x - max(0,mn)
            posnonpu= mx - x
        else: # Plot is on neg. Pos side is empty.
            posnonpu= mx - max(0,mn) # But still show some empty pos.
    nnc= int(negnonpu/upw)*u'-'
    npc= int(negpu/upw)*c
    ppc= int(pospu/upw)*c
    pnc= int(posnonpu/upw)*u'_'
    return u'[%s]' % (nnc+npc+ppc+pnc)
def bargraph ( x , mn , mx , w , c = u'X' ) : if not w : return u'' # No width! if x < mn : x = mn # Clip to bounds. if x > mx : x = mx # Clip to bounds. tx = mx - mn # Total real units possible to show on graph. if tx <= 0 : return u'backwards' # Stupid bounds. upw = tx / float ( w ) # X Units per output char width. if upw <= 0 : return u'what?' # Don't let this happen. negpu , pospu , negnonpu , posnonpu = 0 , 0 , 0 , 0 if mn < 0 : # Then there is a negative part to graph. if x < 0 : # And the plot is on the negative side. negpu = - x + min ( 0 , mx ) negnonpu = - mn + x else : # Plot is on pos. Neg side is empty. negnonpu = - mn + min ( 0 , mx ) # But still show some empty neg. if mx > 0 : # There is a positive part to the graph if x > 0 : # And the plot is on the positive side. pospu = x - max ( 0 , mn ) posnonpu = mx - x else : # Plot is on neg. Pos side is empty. posnonpu = mx - max ( 0 , mn ) # But still show some empty pos. nnc = int ( negnonpu / upw ) * u'-' npc = int ( negpu / upw ) * c ppc = int ( pospu / upw ) * c pnc = int ( posnonpu / upw ) * u'_' return u'[%s]' % ( nnc + npc + ppc + pnc )