FAQ
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
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

## Search Discussions

•  at Jul 12, 2011 at 1:06 am ⇧
I have a histogram script in Python at
http://stromberg.dnsalias.org/svn/histogram/trunk/ It's under a UCI
(BSD-like) license. Feel free to use it or borrow ideas from it.
On Mon, Jul 11, 2011 at 5:42 PM, Cathy James wrote:

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
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
--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110711/8871108b/attachment.html>
•  at Jul 12, 2011 at 5:50 am ⇧
* 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
am a few steps ahead, but stuck for now.
This sounds like homework. There's the Python Tutor mailing list where

Thorsten

## Related Discussions

Discussion Overview
 group python-list categories python posted Jul 12, '11 at 12:42a active Jul 12, '11 at 5:50a posts 3 users 3 website python.org

### 3 users in discussion

Content

People

Support

Translate

site design / logo © 2022 Grokbase