mpl_code_Dashpot.py 5.8 KB

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