Surface NMR processing and inversion GUI
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mydynamicmplcanvas.py 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. from __future__ import unicode_literals
  2. import sys
  3. import os
  4. import random
  5. import matplotlib
  6. # Make sure that we are using QT5
  7. matplotlib.use('Qt5Agg')
  8. from PyQt5 import QtCore, QtWidgets
  9. from numpy import arange, sin, pi
  10. from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  11. from matplotlib.figure import Figure
  12. import numpy as np
  13. class MyMplCanvas(FigureCanvas):
  14. """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
  15. def __init__(self, parent=None, width=3, height=4, dpi=100):
  16. self.fig = Figure(figsize=(width, height), dpi=dpi, facecolor='darkgrey')
  17. #self.fig.patch.set_facecolor('blue')
  18. FigureCanvas.__init__(self, self.fig)
  19. self.setParent(parent)
  20. FigureCanvas.updateGeometry(self)
  21. def compute_initial_figure(self):
  22. pass
  23. def clicked(self):
  24. print ("Clicked")
  25. class MyDynamicMplCanvas(MyMplCanvas):
  26. """A canvas that updates itself every second with a new plot."""
  27. def __init__(self, *args, **kwargs):
  28. MyMplCanvas.__init__(self, *args, **kwargs)
  29. self.ax1 = self.fig.add_axes([.125,.1,.725,.8])
  30. self.ax2 = self.ax1.twinx() # fig.add_axes([.125,.1,.725,.8])
  31. self.compute_initial_figure()
  32. def reAxH(self, num, shx=True, shy=True):
  33. try:
  34. for ax in fig.axes:
  35. self.fig.delaxes(ax)
  36. except:
  37. pass
  38. try:
  39. self.fig.clear()
  40. except:
  41. pass
  42. for n in range(num):
  43. if n == 0:
  44. self.ax1 = self.fig.add_subplot( 1, num, 1)
  45. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  46. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  47. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='x')
  48. self.ax1.yaxis.get_offset_text().set_size(8)
  49. self.ax1.xaxis.get_offset_text().set_size(8)
  50. if n == 1:
  51. self.ax2 = self.fig.add_subplot( 1, num, 2)
  52. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  53. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  54. self.ax2.yaxis.get_offset_text().set_size(8)
  55. if n == 2:
  56. self.ax3 = self.fig.add_subplot( 1, num, 3)
  57. self.ax3.tick_params(axis='both', which='major', labelsize=8)
  58. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  59. self.ax3.yaxis.get_offset_text().set_size(8)
  60. if n == 3:
  61. self.ax4 = self.fig.add_subplot( 1, num, 4)
  62. self.ax4.tick_params(axis='both', which='major', labelsize=8)
  63. self.ax4.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  64. self.ax4.yaxis.get_offset_text().set_size(8)
  65. def reAxH2(self, num, shx=True, shy=True):
  66. try:
  67. for ax in fig.axes:
  68. self.fig.delaxes(ax)
  69. except:
  70. pass
  71. try:
  72. self.fig.clear()
  73. except:
  74. pass
  75. for n in range(num):
  76. if n == 0:
  77. self.ax1 = self.fig.add_subplot( 2, num, 1)
  78. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  79. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  80. self.ax1.yaxis.get_offset_text().set_size(8)
  81. self.ax21 = self.fig.add_subplot( 2, num, num+1)
  82. self.ax21.tick_params(axis='both', which='major', labelsize=8)
  83. self.ax21.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  84. self.ax21.yaxis.get_offset_text().set_size(8)
  85. if n == 1:
  86. self.ax2 = self.fig.add_subplot( 2, num, 2, sharex=self.ax1, sharey=self.ax1)
  87. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  88. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  89. self.ax2.yaxis.get_offset_text().set_size(8)
  90. self.ax22 = self.fig.add_subplot( 2, num, num+2, sharex=self.ax21, sharey=self.ax21)
  91. self.ax22.tick_params(axis='both', which='major', labelsize=8)
  92. self.ax22.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  93. self.ax22.yaxis.get_offset_text().set_size(8)
  94. if n == 2:
  95. self.ax3 = self.fig.add_subplot( 2, num, 3, sharex=self.ax1, sharey=self.ax1)
  96. self.ax3.tick_params(axis='both', which='major', labelsize=8)
  97. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  98. self.ax3.yaxis.get_offset_text().set_size(8)
  99. self.ax23 = self.fig.add_subplot( 2, num, num+3, sharex=self.ax21, sharey=self.ax21)
  100. self.ax23.tick_params(axis='both', which='major', labelsize=8)
  101. self.ax23.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  102. self.ax23.yaxis.get_offset_text().set_size(8)
  103. if n == 3:
  104. self.ax4 = self.fig.add_subplot( 2, num, 4, sharex=self.ax1, sharey=self.ax1 )
  105. self.ax4.tick_params(axis='both', which='major', labelsize=8)
  106. self.ax4.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  107. self.ax4.yaxis.get_offset_text().set_size(8)
  108. self.ax24 = self.fig.add_subplot( 2, num, num+4, sharex=self.ax21, sharey=self.ax21 )
  109. self.ax24.tick_params(axis='both', which='major', labelsize=8)
  110. self.ax24.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  111. self.ax24.yaxis.get_offset_text().set_size(8)
  112. if n == 4:
  113. self.ax5 = self.fig.add_subplot( 2, num, 5, sharex=self.ax1, sharey=self.ax1 )
  114. self.ax5.tick_params(axis='both', which='major', labelsize=8)
  115. self.ax5.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  116. self.ax5.yaxis.get_offset_text().set_size(8)
  117. self.ax25 = self.fig.add_subplot( 2, num, num+5, sharex=self.ax21, sharey=self.ax21 )
  118. self.ax25.tick_params(axis='both', which='major', labelsize=8)
  119. self.ax25.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  120. self.ax25.yaxis.get_offset_text().set_size(8)
  121. if n == 5:
  122. self.ax6 = self.fig.add_subplot( 2, num, 6, sharex=self.ax1, sharey=self.ax1 )
  123. self.ax6.tick_params(axis='both', which='major', labelsize=8)
  124. self.ax6.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  125. self.ax6.yaxis.get_offset_text().set_size(8)
  126. self.ax26 = self.fig.add_subplot( 2, num, num+6, sharex=self.ax21, sharey=self.ax21 )
  127. self.ax26.tick_params(axis='both', which='major', labelsize=8)
  128. self.ax26.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  129. self.ax26.yaxis.get_offset_text().set_size(8)
  130. if n == 6:
  131. self.ax7 = self.fig.add_subplot( 2, num, 7, sharex=self.ax1, sharey=self.ax1 )
  132. self.ax7.tick_params(axis='both', which='major', labelsize=8)
  133. self.ax7.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  134. self.ax7.yaxis.get_offset_text().set_size(8)
  135. self.ax27 = self.fig.add_subplot( 2, num, num+7, sharex=self.ax21, sharey=self.ax21 )
  136. self.ax27.tick_params(axis='both', which='major', labelsize=8)
  137. self.ax27.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  138. self.ax27.yaxis.get_offset_text().set_size(8)
  139. if n == 7:
  140. self.ax8 = self.fig.add_subplot( 2, num, 8, sharex=self.ax1, sharey=self.ax1 )
  141. self.ax8.tick_params(axis='both', which='major', labelsize=8)
  142. self.ax8.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  143. self.ax8.yaxis.get_offset_text().set_size(8)
  144. self.ax28 = self.fig.add_subplot( 2, num, num+8, sharex=self.ax21, sharey=self.ax21 )
  145. self.ax28.tick_params(axis='both', which='major', labelsize=8)
  146. self.ax28.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  147. self.ax28.yaxis.get_offset_text().set_size(8)
  148. def reAx2(self, shx=True, shy=True):
  149. try:
  150. self.fig.clear()
  151. except:
  152. pass
  153. try:
  154. self.ax1.clear()
  155. self.delaxes(self.ax1) #.clear()
  156. except:
  157. pass
  158. try:
  159. self.delaxes(self.ax3) #.clear()
  160. except:
  161. pass
  162. try:
  163. self.ax2.clear()
  164. self.delaxes(self.ax2) #.clear()
  165. except:
  166. pass
  167. #self.fig.patch.set_facecolor('red')
  168. self.ax1 = self.fig.add_subplot(211)
  169. if shx and shy:
  170. self.ax2 = self.fig.add_subplot(212, sharex=self.ax1, sharey=self.ax1)
  171. elif shx == True:
  172. self.ax2 = self.fig.add_subplot(212, sharex=self.ax1)
  173. elif shy == True:
  174. self.ax2 = self.fig.add_subplot(212, sharey=self.ax1)
  175. else:
  176. self.ax2 = self.fig.add_subplot(212)
  177. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  178. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  179. self.ax1.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')
  180. self.ax2.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')
  181. self.ax1.yaxis.get_offset_text().set_size(8)
  182. self.ax2.yaxis.get_offset_text().set_size(8)
  183. def softClear(self):
  184. for ax in self.fig.get_axes():
  185. for artist in ax.lines + ax.collections:
  186. artist.remove()
  187. ax.set_prop_cycle(None)
  188. def reAx3(self, shx=True, shy=True):
  189. try:
  190. self.fig.clear()
  191. except:
  192. pass
  193. try:
  194. self.ax1.clear()
  195. self.delaxes(self.ax1) #.clear()
  196. except:
  197. pass
  198. try:
  199. self.ax2.clear()
  200. self.delaxes(self.ax2) #.clear()
  201. except:
  202. pass
  203. try:
  204. self.ax3.clear()
  205. self.delaxes(self.ax3) #.clear()
  206. except:
  207. pass
  208. self.ax2 = self.fig.add_subplot(211)
  209. if shx and shy:
  210. self.ax1 = self.fig.add_subplot(212, sharex=self.ax2, sharey=self.ax2)
  211. elif shx:
  212. self.ax1 = self.fig.add_subplot(212, sharex=self.ax2)
  213. elif shy:
  214. self.ax1 = self.fig.add_subplot(212, sharey=self.ax2)
  215. else:
  216. self.ax1 = self.fig.add_subplot(212)
  217. self.ax3 = self.ax1.twinx()
  218. self.ax2.yaxis.set_label_position("right")
  219. self.ax2.yaxis.set_ticks_position("right")
  220. #self.ax2.yaxis.tick_right()
  221. #self.ax1.set_facecolor('red')
  222. #self.ax2.set_facecolor('red')
  223. #self.ax3.set_facecolor('red')
  224. #self.fig.set_facecolor('red')
  225. #self.fig.set_edgecolor('red')
  226. #self.ax1.set_axis_bgcolor('green')
  227. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  228. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  229. self.ax3.tick_params(axis='both', which='major', labelsize=8)
  230. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  231. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  232. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  233. self.ax1.yaxis.get_offset_text().set_size(8)
  234. self.ax2.yaxis.get_offset_text().set_size(8)
  235. self.ax3.yaxis.get_offset_text().set_size(8)
  236. def reAx4(self):
  237. try:
  238. self.fig.clear()
  239. except:
  240. pass
  241. # two main axes
  242. self.ax1 = self.fig.add_axes([0.15, 0.55, 0.625, 0.3672])
  243. self.ax2 = self.fig.add_axes([0.15, 0.135, 0.625, 0.3672])
  244. # for colourbars
  245. self.cax1 = self.fig.add_axes([0.8, 0.55, 0.025, 0.3672])
  246. self.cax2 = self.fig.add_axes([0.8, 0.135, 0.025, 0.3672])
  247. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  248. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  249. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  250. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  251. self.ax1.yaxis.get_offset_text().set_size(8)
  252. self.ax2.yaxis.get_offset_text().set_size(8)
  253. self.cax1.tick_params(axis='both', which='major', labelsize=8)
  254. self.cax2.tick_params(axis='both', which='major', labelsize=8)
  255. self.cax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  256. self.cax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  257. self.cax1.yaxis.get_offset_text().set_size(8) #.get_text()
  258. self.cax2.yaxis.get_offset_text().set_size(8) #.get_text()
  259. self.cax1.tick_params(labelsize=8)
  260. self.cax2.tick_params(labelsize=8)
  261. def compute_initial_figure(self):
  262. t = np.arange(0,.3,1e-4)
  263. x = np.cos(t*2000.*np.pi*2)*np.exp(-t/.07)
  264. x2 = np.exp(-t/.07)
  265. dp = self.ax1.plot(t, x, 'r',label='test function')
  266. dp2 = self.ax2.plot(t, x2, 'r',label='test function2')
  267. self.ax1.set_xlabel("Time [s]", fontsize=8)
  268. self.ax1.set_ylabel("Signal [nV]", fontsize=8)
  269. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  270. self.ax1.tick_params(axis='both', which='minor', labelsize=6)
  271. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  272. self.ax1.legend(prop={'size':6})