Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9297

Please Help with vertical histogram

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <nambo4jb@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.039
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'else:': 0.03; 'help?': 0.03; 'dict': 0.09; 'indexes': 0.09; 'pulled': 0.09; '#get': 0.16; "'>'": 0.16; 'this:': 0.16; 'def': 0.16; 'subject:Help': 0.17; 'axis': 0.23; 'right.': 0.28; 'message-id:@mail.gmail.com': 0.28; 'print': 0.32; 'to:addr:python-list': 0.34; 'someone': 0.34; "can't": 0.34; 'project': 0.35; 'stuck': 0.35; 'minimum': 0.37; 'subject:Please': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'two': 0.38; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'skip:- 50': 0.40; 'received:209': 0.40; 'where': 0.40; 'maximum': 0.62; 'results': 0.62; 'kindly': 0.65; '100': 0.72; 'received:209.85.216.174': 0.73; 'weeks,': 0.73; "'|'": 0.84; 'hair': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=G6XW6zFBK7736F3Y8vJnjP7Wd/ArK/rSyQXYtoFgOcA=; b=QFyko6kCuo31TgjubjzHZrFef/f4FKs2YN0uSbUDiNecAvT+zaqdmJrPR0vbiSAJMY MwOXcMe5a+geYNUox1XVnNBNyjVFhjO18Z2KnHtzxtPS1LXZbcHgMWGXzAyNgiyCuZ3f G5kohYkDTDbf+LACIrgSrUbJ3Rr0dzXFJochw=
MIME-Version 1.0
Date Mon, 11 Jul 2011 19:42:10 -0500
Subject Please Help with vertical histogram
From Cathy James <nambo4jb@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.931.1310431333.1164.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310431333 news.xs4all.nl 21862 [2001:888:2000:d::a6]:60852
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9297

Show key headers only | View raw


Please kindly help- i have a project where I need to plot dict results
as a histogram. I just can't get the y- axis to print right.  May
someone please help?  I have pulled my hair for the past two weeks, I
am a few steps ahead, but stuck for now.


def histo(his_dict = {1:16, 2:267, 3:267, 4:169, 5:140, 6:112, 7:99,
8:68, 9:61, 10:56, 11:35, 12:13, 13:9, 14: 7, 15:2}):

    x_max = 17 #get maximum value of x
    y_max = 400 #get minimum value of y
    # print each line
    print ('^')
    for j in range(y_max, 0, -100):# draw

        s = '|'
        for i in range(1, x_max):
            if i in his_dict.keys() and his_dict[i] >= j:
                s += '***'
            else:
                s += '   '
        print (s)
        print (j)
        # print x axis
    s = '+'
    for i in range(1, x_max):
        s += '-+-'
    s += '>'
    print (s)

    # print indexes
    s = ' '
    for i in range(1, x_max):
        s += ' %d ' % i
    print (s)

histo()

# I need it to look like this:
400 -|
       |
       |
       |
       |
300 -|
       |
       |   ******
       |   ******
       |   ******
200 -|   ******
       |   ******
       |   *********
       |   ************
       |   ************
100 -|   ***************
       |   ******************
       |   ************************
       |   ***************************
       |*********************************
    0 -+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
       | 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Please Help with vertical histogram Cathy James <nambo4jb@gmail.com> - 2011-07-11 19:42 -0500
  Re: Please Help with vertical histogram Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-07-12 07:50 +0200

csiph-web