Surface NMR processing and inversion GUI
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mydynamicmplcanvas.py 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. fs = 10
  34. try:
  35. for ax in fig.axes:
  36. self.fig.delaxes(ax)
  37. except:
  38. pass
  39. try:
  40. self.fig.clear()
  41. except:
  42. pass
  43. for n in range(num):
  44. if n == 0:
  45. self.ax1 = self.fig.add_subplot( 1, num, 1)
  46. self.ax1.tick_params(axis='both', which='major', labelsize=fs)
  47. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  48. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='x')
  49. self.ax1.yaxis.get_offset_text().set_size(fs)
  50. self.ax1.xaxis.get_offset_text().set_size(fs)
  51. if n == 1:
  52. self.ax2 = self.fig.add_subplot( 1, num, 2)
  53. self.ax2.tick_params(axis='both', which='major', labelsize=fs)
  54. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  55. self.ax2.yaxis.get_offset_text().set_size(fs)
  56. if n == 2:
  57. self.ax3 = self.fig.add_subplot( 1, num, 3)
  58. self.ax3.tick_params(axis='both', which='major', labelsize=fs)
  59. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  60. self.ax3.yaxis.get_offset_text().set_size(fs)
  61. if n == 3:
  62. self.ax4 = self.fig.add_subplot( 1, num, 4)
  63. self.ax4.tick_params(axis='both', which='major', labelsize=fs)
  64. self.ax4.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  65. self.ax4.yaxis.get_offset_text().set_size(fs)
  66. def reAxH2(self, num, shx=True, shy=True):
  67. fs = 10
  68. try:
  69. for ax in fig.axes:
  70. self.fig.delaxes(ax)
  71. except:
  72. pass
  73. try:
  74. self.fig.clear()
  75. except:
  76. pass
  77. for n in range(num):
  78. if n == 0:
  79. self.ax1 = self.fig.add_subplot( 2, num, 1)
  80. self.ax1.tick_params(axis='both', which='major', labelsize=fs)
  81. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  82. self.ax1.yaxis.get_offset_text().set_size(fs)
  83. self.ax21 = self.fig.add_subplot( 2, num, num+1)
  84. self.ax21.tick_params(axis='both', which='major', labelsize=fs)
  85. self.ax21.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  86. self.ax21.yaxis.get_offset_text().set_size(fs)
  87. if n == 1:
  88. self.ax2 = self.fig.add_subplot( 2, num, 2, sharex=self.ax1, sharey=self.ax1)
  89. self.ax2.tick_params(axis='both', which='major', labelsize=fs)
  90. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  91. self.ax2.yaxis.get_offset_text().set_size(fs)
  92. self.ax22 = self.fig.add_subplot( 2, num, num+2, sharex=self.ax21, sharey=self.ax21)
  93. self.ax22.tick_params(axis='both', which='major', labelsize=fs)
  94. self.ax22.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  95. self.ax22.yaxis.get_offset_text().set_size(fs)
  96. if n == 2:
  97. self.ax3 = self.fig.add_subplot( 2, num, 3, sharex=self.ax1, sharey=self.ax1)
  98. self.ax3.tick_params(axis='both', which='major', labelsize=fs)
  99. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  100. self.ax3.yaxis.get_offset_text().set_size(fs)
  101. self.ax23 = self.fig.add_subplot( 2, num, num+3, sharex=self.ax21, sharey=self.ax21)
  102. self.ax23.tick_params(axis='both', which='major', labelsize=fs)
  103. self.ax23.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  104. self.ax23.yaxis.get_offset_text().set_size(fs)
  105. if n == 3:
  106. self.ax4 = self.fig.add_subplot( 2, num, 4, sharex=self.ax1, sharey=self.ax1 )
  107. self.ax4.tick_params(axis='both', which='major', labelsize=fs)
  108. self.ax4.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  109. self.ax4.yaxis.get_offset_text().set_size(fs)
  110. self.ax24 = self.fig.add_subplot( 2, num, num+4, sharex=self.ax21, sharey=self.ax21 )
  111. self.ax24.tick_params(axis='both', which='major', labelsize=fs)
  112. self.ax24.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  113. self.ax24.yaxis.get_offset_text().set_size(fs)
  114. if n == 4:
  115. self.ax5 = self.fig.add_subplot( 2, num, 5, sharex=self.ax1, sharey=self.ax1 )
  116. self.ax5.tick_params(axis='both', which='major', labelsize=8)
  117. self.ax5.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  118. self.ax5.yaxis.get_offset_text().set_size(8)
  119. self.ax25 = self.fig.add_subplot( 2, num, num+5, sharex=self.ax21, sharey=self.ax21 )
  120. self.ax25.tick_params(axis='both', which='major', labelsize=8)
  121. self.ax25.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  122. self.ax25.yaxis.get_offset_text().set_size(8)
  123. if n == 5:
  124. self.ax6 = self.fig.add_subplot( 2, num, 6, sharex=self.ax1, sharey=self.ax1 )
  125. self.ax6.tick_params(axis='both', which='major', labelsize=8)
  126. self.ax6.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  127. self.ax6.yaxis.get_offset_text().set_size(8)
  128. self.ax26 = self.fig.add_subplot( 2, num, num+6, sharex=self.ax21, sharey=self.ax21 )
  129. self.ax26.tick_params(axis='both', which='major', labelsize=8)
  130. self.ax26.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  131. self.ax26.yaxis.get_offset_text().set_size(8)
  132. if n == 6:
  133. self.ax7 = self.fig.add_subplot( 2, num, 7, sharex=self.ax1, sharey=self.ax1 )
  134. self.ax7.tick_params(axis='both', which='major', labelsize=8)
  135. self.ax7.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  136. self.ax7.yaxis.get_offset_text().set_size(8)
  137. self.ax27 = self.fig.add_subplot( 2, num, num+7, sharex=self.ax21, sharey=self.ax21 )
  138. self.ax27.tick_params(axis='both', which='major', labelsize=8)
  139. self.ax27.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  140. self.ax27.yaxis.get_offset_text().set_size(8)
  141. if n == 7:
  142. self.ax8 = self.fig.add_subplot( 2, num, 8, sharex=self.ax1, sharey=self.ax1 )
  143. self.ax8.tick_params(axis='both', which='major', labelsize=8)
  144. self.ax8.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  145. self.ax8.yaxis.get_offset_text().set_size(8)
  146. self.ax28 = self.fig.add_subplot( 2, num, num+8, sharex=self.ax21, sharey=self.ax21 )
  147. self.ax28.tick_params(axis='both', which='major', labelsize=8)
  148. self.ax28.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  149. self.ax28.yaxis.get_offset_text().set_size(8)
  150. def reAx2(self, shx=True, shy=True):
  151. try:
  152. self.fig.clear()
  153. except:
  154. pass
  155. try:
  156. self.ax1.clear()
  157. self.delaxes(self.ax1) #.clear()
  158. except:
  159. pass
  160. try:
  161. self.delaxes(self.ax3) #.clear()
  162. except:
  163. pass
  164. try:
  165. self.ax2.clear()
  166. self.delaxes(self.ax2) #.clear()
  167. except:
  168. pass
  169. #self.fig.patch.set_facecolor('red')
  170. self.ax1 = self.fig.add_subplot(211)
  171. if shx and shy:
  172. self.ax2 = self.fig.add_subplot(212, sharex=self.ax1, sharey=self.ax1)
  173. elif shx == True:
  174. self.ax2 = self.fig.add_subplot(212, sharex=self.ax1)
  175. elif shy == True:
  176. self.ax2 = self.fig.add_subplot(212, sharey=self.ax1)
  177. else:
  178. self.ax2 = self.fig.add_subplot(212)
  179. self.ax1.tick_params(axis='both', which='major', labelsize=10)
  180. self.ax2.tick_params(axis='both', which='major', labelsize=10)
  181. self.ax1.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')
  182. self.ax2.ticklabel_format(style='scientific', scilimits=(0,0), axis='y')
  183. self.ax1.yaxis.get_offset_text().set_size(10)
  184. self.ax2.yaxis.get_offset_text().set_size(10)
  185. def softClear(self):
  186. for ax in self.fig.get_axes():
  187. for artist in ax.lines + ax.collections:
  188. artist.remove()
  189. ax.set_prop_cycle(None)
  190. def reAx3(self, shx=True, shy=True):
  191. fs = 10
  192. try:
  193. self.fig.clear()
  194. except:
  195. pass
  196. try:
  197. self.ax1.clear()
  198. self.delaxes(self.ax1) #.clear()
  199. except:
  200. pass
  201. try:
  202. self.ax2.clear()
  203. self.delaxes(self.ax2) #.clear()
  204. except:
  205. pass
  206. try:
  207. self.ax3.clear()
  208. self.delaxes(self.ax3) #.clear()
  209. except:
  210. pass
  211. self.ax2 = self.fig.add_subplot(211)
  212. if shx and shy:
  213. self.ax1 = self.fig.add_subplot(212, sharex=self.ax2, sharey=self.ax2)
  214. elif shx:
  215. self.ax1 = self.fig.add_subplot(212, sharex=self.ax2)
  216. elif shy:
  217. self.ax1 = self.fig.add_subplot(212, sharey=self.ax2)
  218. else:
  219. self.ax1 = self.fig.add_subplot(212)
  220. self.ax3 = self.ax1.twinx()
  221. self.ax2.yaxis.set_label_position("right")
  222. self.ax2.yaxis.set_ticks_position("right")
  223. #self.ax2.yaxis.tick_right()
  224. #self.ax1.set_facecolor('red')
  225. #self.ax2.set_facecolor('red')
  226. #self.ax3.set_facecolor('red')
  227. #self.fig.set_facecolor('red')
  228. #self.fig.set_edgecolor('red')
  229. #self.ax1.set_axis_bgcolor('green')
  230. self.ax1.tick_params(axis='both', which='major', labelsize=fs)
  231. self.ax2.tick_params(axis='both', which='major', labelsize=fs)
  232. self.ax3.tick_params(axis='both', which='major', labelsize=fs)
  233. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  234. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  235. self.ax3.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  236. self.ax1.yaxis.get_offset_text().set_size(fs)
  237. self.ax2.yaxis.get_offset_text().set_size(fs)
  238. self.ax3.yaxis.get_offset_text().set_size(fs)
  239. def reAx4(self):
  240. try:
  241. self.fig.clear()
  242. except:
  243. pass
  244. # two main axes
  245. self.ax1 = self.fig.add_axes([0.15, 0.55, 0.625, 0.3672])
  246. self.ax2 = self.fig.add_axes([0.15, 0.135, 0.625, 0.3672])
  247. # for colourbars
  248. self.cax1 = self.fig.add_axes([0.8, 0.55, 0.025, 0.3672])
  249. self.cax2 = self.fig.add_axes([0.8, 0.135, 0.025, 0.3672])
  250. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  251. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  252. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  253. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  254. self.ax1.yaxis.get_offset_text().set_size(8)
  255. self.ax2.yaxis.get_offset_text().set_size(8)
  256. self.cax1.tick_params(axis='both', which='major', labelsize=8)
  257. self.cax2.tick_params(axis='both', which='major', labelsize=8)
  258. self.cax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  259. self.cax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  260. self.cax1.yaxis.get_offset_text().set_size(8) #.get_text()
  261. self.cax2.yaxis.get_offset_text().set_size(8) #.get_text()
  262. self.cax1.tick_params(labelsize=8)
  263. self.cax2.tick_params(labelsize=8)
  264. def compute_initial_figure(self):
  265. t = np.arange(0,.3,1e-4)
  266. x = np.cos(t*2000.*np.pi*2)*np.exp(-t/.07)
  267. x2 = np.exp(-t/.07)
  268. dp = self.ax1.plot(t, x, 'r',label='test function')
  269. dp2 = self.ax2.plot(t, x2, 'r',label='test function2')
  270. self.ax1.set_xlabel("Time [s]", fontsize=8)
  271. self.ax1.set_ylabel("Signal [nV]", fontsize=8)
  272. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  273. self.ax1.tick_params(axis='both', which='minor', labelsize=6)
  274. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  275. self.ax1.legend(prop={'size':6})