res_Dashpot.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import matplotlib.pyplot as mpl
  2. mpl.ion() # for interactive drawing
  3. fig = mpl.figure()
  4. ax = fig.gca()
  5. xmin, xmax, ymin, ymax = 0.0, 11.0, -2.5, 7.5
  6. ax.set_xlim(xmin, xmax)
  7. ax.set_ylim(ymin, ymax)
  8. ax.set_aspect('equal')
  9. mpl.grid(True)
  10. x = [1.5, 1.5]
  11. y = [0.0, 1.25]
  12. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  13. x = [1.5, 1.5]
  14. y = [5.0, 2.395833333333333]
  15. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  16. x = [1.0833333333333333,
  17. 1.9166666666666665,
  18. 1.9166666666666665,
  19. 1.0833333333333333,
  20. 1.0833333333333333]
  21. y = [2.083333333333333,
  22. 2.083333333333333,
  23. 2.395833333333333,
  24. 2.395833333333333,
  25. 2.083333333333333]
  26. ax.fill(x, y, 'white', edgecolor='b', linewidth=2, hatch='X')
  27. x = [1.0, 1.0, 2.0, 2.0]
  28. y = [3.75, 1.25, 1.25, 3.75]
  29. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  30. ax.text(1.5, 5.5, 'Dashpot (default)',
  31. horizontalalignment='center', fontsize=14)
  32. x = [6.5, 6.5]
  33. y = [0.0, 2.0]
  34. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  35. x = [6.5, 6.5]
  36. y = [6.0, 4.5]
  37. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  38. x = [6.083333333333333,
  39. 6.916666666666666,
  40. 6.916666666666666,
  41. 6.083333333333333,
  42. 6.083333333333333]
  43. y = [4.1875, 4.1875, 4.5, 4.5, 4.1875]
  44. ax.fill(x, y, 'white', edgecolor='b', linewidth=2, hatch='X')
  45. x = [6.0, 6.0, 7.0, 7.0]
  46. y = [4.5, 2.0, 2.0, 4.5]
  47. ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  48. ax.text(6.5, -1.56667, 'width',
  49. horizontalalignment='center', fontsize=14)
  50. x = [7.0, 6.0]
  51. y = [-1.75, -1.75]
  52. ax.plot(x, y, 'k', linewidth=1, linestyle='solid')
  53. mpl.arrow(x=6, y=-1.75, dx=1, dy=0,
  54. facecolor='k', edgecolor='k',
  55. linewidth=1, head_width=0.1,
  56. length_includes_head=True,
  57. shape='full')
  58. mpl.arrow(x=7, y=-1.75, dx=-1, dy=0,
  59. facecolor='k', edgecolor='k',
  60. linewidth=1, head_width=0.1,
  61. length_includes_head=True,
  62. shape='full')
  63. ax.annotate('start', xy=(6.5, 0), xycoords='data',
  64. textcoords='data', xytext=(5.75, -0.75),
  65. horizontalalignment='center',
  66. verticalalignment='top',
  67. fontsize=14,
  68. arrowprops=dict(arrowstyle='->',
  69. facecolor='black',
  70. linewidth=2,
  71. shrinkA=5,
  72. shrinkB=5))
  73. ax.annotate('bar_length', xy=[ 5.5 1. ], xycoords='data',
  74. textcoords='data', xytext=(3.5, 1.5),
  75. horizontalalignment='left',
  76. verticalalignment='top',
  77. fontsize=14,
  78. arrowprops=dict(arrowstyle='->',
  79. facecolor='black',
  80. linewidth=2,
  81. shrinkA=5,
  82. shrinkB=5))
  83. x = [5.5, 5.5]
  84. y = [0.0, 2.0]
  85. ax.plot(x, y, 'k', linewidth=1, linestyle='solid')
  86. mpl.arrow(x=5.5, y=2, dx=0, dy=-2,
  87. facecolor='k', edgecolor='k',
  88. linewidth=1, head_width=0.1,
  89. length_includes_head=True,
  90. shape='full')
  91. mpl.arrow(x=5.5, y=0, dx=0, dy=2,
  92. facecolor='k', edgecolor='k',
  93. linewidth=1, head_width=0.1,
  94. length_includes_head=True,
  95. shape='full')
  96. ax.annotate('total_length', xy=[ 8.5 3. ], xycoords='data',
  97. textcoords='data', xytext=(8.75, 5.0),
  98. horizontalalignment='left',
  99. verticalalignment='top',
  100. fontsize=14,
  101. arrowprops=dict(arrowstyle='->',
  102. facecolor='black',
  103. linewidth=2,
  104. shrinkA=5,
  105. shrinkB=5))
  106. x = [8.5, 8.5]
  107. y = [0.0, 6.0]
  108. ax.plot(x, y, 'k', linewidth=1, linestyle='solid')
  109. mpl.arrow(x=8.5, y=6, dx=0, dy=-6,
  110. facecolor='k', edgecolor='k',
  111. linewidth=1, head_width=0.1,
  112. length_includes_head=True,
  113. shape='full')
  114. mpl.arrow(x=8.5, y=0, dx=0, dy=6,
  115. facecolor='k', edgecolor='k',
  116. linewidth=1, head_width=0.1,
  117. length_includes_head=True,
  118. shape='full')
  119. ax.annotate('dashpot_length', xy=[ 7.5 3.25], xycoords='data',
  120. textcoords='data', xytext=(7.0, -0.5),
  121. horizontalalignment='left',
  122. verticalalignment='top',
  123. fontsize=14,
  124. arrowprops=dict(arrowstyle='->',
  125. facecolor='black',
  126. linewidth=2,
  127. shrinkA=5,
  128. shrinkB=5))
  129. x = [7.5, 7.5]
  130. y = [2.0, 4.5]
  131. ax.plot(x, y, 'k', linewidth=1, linestyle='solid')
  132. mpl.arrow(x=7.5, y=4.5, dx=0, dy=-2.5,
  133. facecolor='k', edgecolor='k',
  134. linewidth=1, head_width=0.1,
  135. length_includes_head=True,
  136. shape='full')
  137. mpl.arrow(x=7.5, y=2, dx=0, dy=2.5,
  138. facecolor='k', edgecolor='k',
  139. linewidth=1, head_width=0.1,
  140. length_includes_head=True,
  141. shape='full')
  142. ax.annotate('piston_pos', xy=[ 5.5 3.09375], xycoords='data',
  143. textcoords='data', xytext=(3.5, 3.6875),
  144. horizontalalignment='left',
  145. verticalalignment='top',
  146. fontsize=14,
  147. arrowprops=dict(arrowstyle='->',
  148. facecolor='black',
  149. linewidth=2,
  150. shrinkA=5,
  151. shrinkB=5))
  152. x = [5.5, 5.5]
  153. y = [2.0, 4.1875]
  154. ax.plot(x, y, 'k', linewidth=1, linestyle='solid')
  155. mpl.arrow(x=5.5, y=4.1875, dx=0, dy=-2.1875,
  156. facecolor='k', edgecolor='k',
  157. linewidth=1, head_width=0.1,
  158. length_includes_head=True,
  159. shape='full')
  160. mpl.arrow(x=5.5, y=2, dx=0, dy=2.1875,
  161. facecolor='k', edgecolor='k',
  162. linewidth=1, head_width=0.1,
  163. length_includes_head=True,
  164. shape='full')
  165. mpl.title("Dashpot")
  166. mpl.draw()
  167. mpl.savefig("tmp_Dashpot.png")