mpl_code_Rectangle.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import matplotlib.pyplot as mpl
  2. import matplotlib.transforms as transforms
  3. mpl.ion() # for interactive drawing
  4. fig = mpl.figure()
  5. ax = fig.gca()
  6. xmin, xmax, ymin, ymax = 0.0, 8.0, -1.5, 6.0
  7. ax.set_xlim(xmin, xmax)
  8. ax.set_ylim(ymin, ymax)
  9. ax.set_aspect('equal')
  10. mpl.grid(True)
  11. # rectangle
  12. x = [2.0, 6.0, 6.0, 2.0, 2.0]
  13. y = [0.0, 0.0, 3.0, 3.0, 0.0]
  14. [line] = ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  15. ax.text(4, -0.466667, 'width',
  16. horizontalalignment='center', fontsize=14)
  17. # line
  18. mpl.arrow(x=2, y=-0.6, dx=4, dy=0,
  19. facecolor='k', edgecolor='k',
  20. linestyle='solid',
  21. linewidth=1, head_width=0.1,
  22. length_includes_head=True,
  23. shape='full')
  24. mpl.arrow(x=6, y=-0.6, dx=-4, dy=0,
  25. facecolor='k', edgecolor='k',
  26. linestyle='solid',
  27. linewidth=1, head_width=0.1,
  28. length_includes_head=True,
  29. shape='full')
  30. ax.annotate('lower_left_corner', xy=[ 2. 0.], xycoords='data',
  31. textcoords='data', xytext=[ 1.2 -0.6],
  32. horizontalalignment='center',
  33. verticalalignment='top',
  34. fontsize=14,
  35. arrowprops=dict(arrowstyle='->',
  36. facecolor='black',
  37. linewidth=2,
  38. shrinkA=5,
  39. shrinkB=5))
  40. ax.text(6.93333, 1.5, 'height',
  41. horizontalalignment='left', fontsize=14)
  42. # line
  43. mpl.arrow(x=6.8, y=3, dx=0, dy=-3,
  44. facecolor='k', edgecolor='k',
  45. linestyle='solid',
  46. linewidth=1, head_width=0.1,
  47. length_includes_head=True,
  48. shape='full')
  49. mpl.arrow(x=6.8, y=0, dx=0, dy=3,
  50. facecolor='k', edgecolor='k',
  51. linestyle='solid',
  52. linewidth=1, head_width=0.1,
  53. length_includes_head=True,
  54. shape='full')
  55. mpl.title("Rectangle")
  56. mpl.draw()
  57. mpl.savefig("tmp_Rectangle.png", dpi=None)
  58. mpl.savefig("tmp_Rectangle.pdf")