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


Groups > comp.lang.python > #9297 > unrolled thread

Please Help with vertical histogram

Started byCathy James <nambo4jb@gmail.com>
First post2011-07-11 19:42 -0500
Last post2011-07-12 07:50 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#9297 — Please Help with vertical histogram

FromCathy James <nambo4jb@gmail.com>
Date2011-07-11 19:42 -0500
SubjectPlease Help with vertical histogram
Message-ID<mailman.931.1310431333.1164.python-list@python.org>
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

[toc] | [next] | [standalone]


#9306

FromThorsten Kampe <thorsten@thorstenkampe.de>
Date2011-07-12 07:50 +0200
Message-ID<MPG.2885ff2143b7deb1989830@news.individual.de>
In reply to#9297
* Cathy James (Mon, 11 Jul 2011 19:42:10 -0500)
> 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.

This sounds like homework. There's the Python Tutor mailing list where 
you will receive help.

Thorsten

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web