notebook.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. __author__ = 'andrey'
  2. def print_stats(items):
  3. if items is None or len(items) < 1:
  4. return
  5. print("\n%-50s (%02d)" % (items[0].__class__.__name__ + "s", len(items)))
  6. for t in set(i.type for i in items):
  7. print("\ttype: %-35s (%02d)" % (t, len([1 for i in items if i.type == t])))
  8. def print_metadata_table(section):
  9. import matplotlib.pyplot as plt
  10. columns = ['Name', 'Value', 'Unit']
  11. cell_text = []
  12. for p in [(i.name, i) for i in section.props]:
  13. for i, v in enumerate(p[1].values):
  14. value = str(v.value)
  15. if len(value) > 30:
  16. value = value[:30] + '...'
  17. if i == 0:
  18. row_data = [p[0], value, p[1].unit if p[1].unit else '-']
  19. else:
  20. row_data = [p[0], value, p[1].unit if p[1].unit else '-']
  21. cell_text.append(row_data)
  22. if len(cell_text) > 0:
  23. nrows, ncols = len(cell_text)+1, len(columns)
  24. hcell, wcell = 1., 5.
  25. hpad, wpad = 0.5, 0
  26. fig = plt.figure(figsize=(ncols*wcell+wpad, nrows*hcell+hpad))
  27. ax = fig.add_subplot(111)
  28. ax.axis('off')
  29. the_table = ax.table(cellText=cell_text,
  30. colLabels=columns,
  31. loc='center')
  32. for cell in the_table.get_children():
  33. cell.set_height(.075)
  34. cell.set_fontsize(12)
  35. #ax.set_title(section.name, fontsize=12)
  36. return fig