-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_beading.py
31 lines (27 loc) · 1.03 KB
/
debug_beading.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
import sys
import ast
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def beadplot(total_thickness, widths, locations):
fig, ax = plt.subplots(1, figsize=(15, 15))
colors = ['g'] * len(widths)
colors[0] = 'r'
colors[-1] = 'r'
for i in range(len(widths)):
l = locations[i]
w = widths[i]
rect = patches.Rectangle(xy=(0, l - w / 2), width=total_thickness, height=w, linewidth=1, edgecolor='k',
facecolor=colors[i], alpha=0.25, label=i)
plt.axhline(y=l, color=colors[i], linestyle='-.')
plt.text(x=total_thickness / 2 - 100, y=l + 5, s=f"idx = {i}\nwidth = {w}", horizontalalignment='center',
verticalalignment='center')
ax.add_patch(rect)
plt.axhline(y=total_thickness / 2, color='k', linestyle='-.')
plt.grid(True)
plt.axis('equal')
plt.xlim([0, total_thickness])
plt.show()
if __name__ == '__main__':
for line in sys.stdin:
parsed = ast.literal_eval(line)
beadplot(**parsed)