1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| try:
import Tkinter as Tk
except:
import Tkinter as tk
def setgraph(v, h=20, bg=None, fill="blue", fic="histo.ps"):
maxheight = max(v)*h
maxwidth = len(v)*h
root = Tk.Tk()
canvas = Tk.Canvas(root, width=maxwidth, height=maxheight)
if bg:
canvas.create_rectangle(0, 0, maxwidth, maxheight, fill=bg)
for i, val in enumerate(v):
canvas.create_rectangle(i*h, maxheight, i*h+h, maxheight-val*h, fill=fill)
canvas.postscript(file=fic, width=maxwidth, height=maxheight, colormode='color')
root.destroy()
values = (5, 6, 7, 2, 1, 20, 18, 12, 5, 7, 8, 9, 12, 5, 6, 7, 2,
1, 20, 18, 12, 5, 7, 8, 9, 12, 5, 6, 7, 2, 1, 20, 18, 12,
5, 7, 8, 9, 12)
setgraph(values, bg="black") |
Partager