Created
April 23, 2018 12:41
-
-
Save secnot/7260425ee4b9fe4cf8da97f35db50b6f to your computer and use it in GitHub Desktop.
Plotting rectpack results using matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more details: http://matthiaseisen.com/pp/patterns/p0203/ | |
for index, abin in enumerate(packer): | |
bw, bh = abin.width, abin.height | |
print('bin', bw, bh, "nr of rectangles in bin", len(abin)) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, aspect='equal') | |
for rect in abin: | |
x, y, w, h = rect.x, rect.y, rect.width, rect.height | |
plt.axis([0,bw,0,bh]) | |
print('rectangle', w,h) | |
ax.add_patch( | |
patches.Rectangle( | |
(x, y), # (x,y) | |
w, # width | |
h, # height | |
facecolor="#00ffff", | |
edgecolor="black", | |
linewidth=3 | |
) | |
) | |
fig.savefig("rect_%(index)s.png" % locals(), dpi=144, bbox_inches='tight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment