-
Notifications
You must be signed in to change notification settings - Fork 0
/
itemplot.py
43 lines (38 loc) · 1.36 KB
/
itemplot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/python
"""
Plot item layouts when given area length, width, and item objects
(having w,l,x,y attributes).
"""
import pylab
def plot_item(item,c,text=None):
x,y,w,h = item.x,item.y,item.w,item.h
pylab.plot([x,x,x+w,x+w,x],[y,y+h,y+h,y,y],c)
if text!=None:
pylab.text(x+w/2,y,str(w), fontsize=8,
horizontalalignment='center',
verticalalignment='bottom',)
pylab.text(x+w,y+h/2,str(h), fontsize=8,
horizontalalignment='right',
verticalalignment='center',)
if h>w:
pylab.text(x+w/3, y+h/2,text, fontsize=8,
horizontalalignment='center',
verticalalignment='center',
rotation=90)
else:
pylab.text(x+w/2, y+h*2./3,text, fontsize=8,
horizontalalignment='center',
verticalalignment='center',)
def plot_layout(items,W,H,show=False,draw=False):
colors = ['r','g','b','c','m','y','k']
if len(items)>0:
pylab.clf()
pylab.axes(aspect='equal')
# plot the board borders
pylab.plot([0,0,0+W,0+W,0],[0,0+H,0+H,0,0],'k',lw=3)
for i,item in enumerate(items):
plot_item(item,colors[i%len(colors)])
if draw:
pylab.draw()
if show:
pylab.show()