spacepaste

  1.  
  2. # -*- coding : utf-8 -*-
  3. from abc import ABCMeta, abstractmethod
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. from abc import ABCMeta, abstractmethod
  7. from cycler import cycler
  8. import matplotlib.font_manager as font_manager
  9. from matplotlib.ticker import MultipleLocator, FormatStrFormatter
  10. from matplotlib.axes import Axes
  11. import matplotlib
  12. from matplotlib import cm
  13. from collections import OrderedDict
  14. from matplotlib.ticker import AutoMinorLocator
  15. class BasePlot(metaclass=ABCMeta):
  16. @abstractmethod
  17. def __init__(self,**kwargs):
  18. self.parameters = kwargs
  19. self.nrows = None
  20. self.ncols = None
  21. self.figsize = None
  22. font_dirs = ['/home/marco/.fonts', ]
  23. font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
  24. font_list = font_manager.createFontList(font_files)
  25. font_manager.fontManager.ttflist.extend(font_list)
  26. #----------------------------------------------------------------------------------------------
  27. def findLimits(self):
  28. '''
  29. found the vectors limits in order to set the figure limits x,y
  30. '''
  31. self._minX = 10E20
  32. self._minY = 10E20
  33. self._maxX = 0.000
  34. self._maxY = 0.000
  35. for i in range(0,len(self.variable)-1,3):
  36. if self._minX >= min(self.variable[i]):
  37. self._minX = min(self.variable[i])
  38. if self._maxX <= max(self.variable[i]):
  39. self._maxX = max(self.variable[i])
  40. if self._minY >= min(self.variable[i+1]):
  41. self._minY = min(self.variable[i+1])
  42. if self._maxY <= max(self.variable[i+1]):
  43. self._maxY = max(self.variable[i+1])
  44. return [round(self._minX,2), round(self._maxX,2) , self._minY, self._maxY]
  45. #return [round(self._minX,2), round(self._maxX,2) , round(self._minY,2) , round(self._maxY,2)]
  46. def schemes(self, style:str = 'nb'):
  47. if style == 'nb':
  48. return ['#8DA0CB', '#E58AC3', '#A6D853', '#FFD930', '#B3B3B3', '#5FC3A4', '#FC8D62', '#E5C494']
  49. elif style == 'nb2': ##7aa0c4","#ca82e1" ,"#8bcd50
  50. return ['#7aa0c4', '#ca82e1', '#8bcd50', '#FFD930', '#B3B3B3', '#5FC3A4', '#FC8D62', '#66C2A5']
  51. elif style == 'nbc': ##7aa0c4","#ca82e1" ,"#8bcd50
  52. return ['#7aa0c4', '#ca82e1', '#8bcd50','#B3B3B3', '#FFD930', '#5FC3A4', '#FC8D62', '#66C2A5']
  53. elif style == 'nbd':
  54. return ['#8DA0CB', '#E58AC3', '#A6D853', '#B3B3B3','#FFD930', '#5FC3A4', '#FC8D62', '#E5C494']
  55. elif style == 'mycolor': ##7aa0c4","#ca82e1" ,"#8bcd50
  56. return ['#7aa0c4', '#ca82e1', '#8bcd50',"#FFD92F", '#B3B3B3',"#64b9a1", "#745ea6", "#db7e76" ]
  57. elif style == 'migcolor':
  58. return ['#66C2A5', '#FC8D62', '#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3']
  59. elif style == 'vega':
  60. return ['#1F77B4', '#FF7F0E', '#2CA02C', '#D62728', '#9467BD', '#8C564B', '#E377C2', '#7F7F7F', '#BCBD22', '#17BECF']
  61. elif style == 'gg':
  62. return ['#E24A33', '#348ABD', '#988ED5', '#777777', '#FBC15E', '#8EBA42', '#FFB5B8']
  63. elif style == 'brewers':
  64. return ['#66C2A5', '#FC8D62', '#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3']
  65. elif style == 'nb2':
  66. return ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62']
  67. # color['nb3'] = ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62']
  68. elif style == 'mystyle':
  69. return ['#8DA0CB', '#E58AC3', '#A6D853', '#FFD930', '#B2B2B2', '#5FC3A4', '#FC8D62', '#66C2A5']
  70. elif style == 'tthmod':
  71. return ['#30a2da', '#fc4f30', '#e5ae38', '#6d904f', '#8b8b8b']
  72. elif style == 'grayscale':
  73. return ['#252525', '#525252', '#737373', '#969696', '#BDBDBD', '#D9D9D9', '#F0F0F0', '#F0F0FF' ]
  74. elif style == 'grayscale2':
  75. return ['#525252', '#969696', '#BDBDBD' ,'#D9D9D9', '#F0F0F0', '#F0F0FF' ]
  76. elif style == 'grayscale3':
  77. return ['#4B4B4B', '#686868', '#868686' ,'#B2B2B2', '#CFCFCF', '#F0F0FF' ]
  78. elif style =='accent':
  79. return ['#7fc97f','#beaed4','#fdc086','#ffff99','#386cb0','#f0027f','#bf5b17','#666666']
  80. elif style == 'palette2':
  81. return ['#1B9E77','#D95F02','#7570B3','#E7298A','#66A61E','#E6AB02','#A6761D','#666666']
  82. elif style == 'set1':
  83. return ['#E41A1C','#377EB8','#4DAF4A','#984EA3','#FF7F00','#FFFF33', '#F781BF','#A65628']
  84. elif style == 'set2':
  85. return ['#66C2A5','#FC8D62','#8DA0CB','#E78AC3','#A6D854','#FFD92F','#E5C494','#B3B3B3']
  86. elif style =='set3':
  87. return ['#8dd3c7','#ffd92f','#bebada','#fb8072','#80b1d3','#fdb462','#b3de69','#fccde5']
  88. elif style =='pastel1':
  89. return ['#b3e2cd','#fdcdac','#cbd5e8','#f4cae4','#e6f5c9','#fff2ae','#f1e2cc','#cccccc']
  90. elif style == 'pastel2':
  91. return ['#fbb4ae','#b3cde3','#ccebc5','#decbe4','#fed9a6','#ffffcc','#e5d8bd','#fddaec']
  92. elif style == 'paraview':
  93. return ['#3B4CC0','#7C9FF9','#C0D4F5','#F2CBB7','#EE8568','#B40426']
  94. elif style =='paraview2':
  95. return ['#3B4CC0','#6889EE','#9ABAFF','#C9D8EF','#EDD1C2','#F7A889','#E26A53','#B40426']
  96. elif style =='radiance1':
  97. return ['#EDED49','#E6B500','#E66300','#E61000','#A40000','#520000','#000000']
  98. elif style =='xray':
  99. return ['#000000','#333333','#666666','#999999','#CCCCCC']
  100. elif style == 'bluesea':
  101. return ['#22204D','#35426B','#3C778F','#4D9BA8','#5DBCBF','#70D4CD','#9DEADA']
  102. elif style == 'bluesky':
  103. return ['#5C5C5C','#59647F','#4D67A0','#4872C4','#5085E3','#62A1F7','#86C1FF','#BFE0FF']
  104. elif style =='bluenice':
  105. return ['#3B4CC0','#4F69D9','#6585EC','#7C9FF9','#93B5FF','#AAC7FD','#C0D4F5','#D4DBE6']
  106. elif style =='paired':
  107. return ['#A6CEE3','#1F78B4','#B2DF8A','#33A02C','#FB9A99','#E31A1C','#FDBF6F','#FF7F00','#CAB2D6','#6A3D9A']
  108. elif style == 'new':
  109. return ['#30A2DA','#FC4F30','#6D904F','#E5AE38','#8B8B8B','#FFB5B8','#988ED5','#30A2DA']
  110. elif style == 'new2':
  111. return ['#0072B2','#A60628','#467821','#F0E442','#7A68A6','#56B4E9','#CC79A7','#009E73']
  112. elif style == 'new3':
  113. return ['#0072B2','#A60628','#467821','#F0E442','#7A68A6','#56B4E9','#CC79A7','#009E73','#348ABD','#D55E00']
  114. elif style == 'new4':
  115. return ['#92C6FF','#FF9F9A','#97F0AA','#FFD92F','#B0E0E6','#D0BBFF','#B8BEAF','#FFB6FC']
  116. elif style == 'new5':
  117. return ['#7A8FB1','#EC9CAE','#B2E295','#FFDFA8','#405C89','#BE4F69','#72B54B','#CFA356']
  118. elif style == 'new6':
  119. return ['#B8CCED','#FBBDCB','#D2F8BB','#FFDA9A']
  120. elif style =='new6a':
  121. return ['#B8CCED','#FBBDCB']
  122. elif style == '3gray':
  123. return ['#000000' , '#000000', '#000000' , '#666666','#666666','#666666', '#999999', '#999999', '#999999']
  124. elif style == '2gray':
  125. return ['#000000' ,'#888A85', '#BABDB6', '#000000','#888A85', '#BABDB6']
  126. elif style == 'grayimproved':
  127. return ['#000000','#808080','#778899','#A9A9A9','#B0C4DE','#C0C0C0']
  128. elif style == 'monocrome':
  129. return ['#000000','#666666','#999999','#B3B3B3']
  130. #------------------------------------------------------------------------------------------
  131. def linestyles(self, style : str = 'ls1'):
  132. if style =='ls1':
  133. return ['-', '--', ':', '-.']
  134. elif style == 'ls2':
  135. return ['-', '--', ':', '-.','-','--',':','-.']
  136. elif style == 'ls3':
  137. return ['-','-','-','-.','-.','-.',':',':',':']
  138. elif style == 'ls3a':
  139. return ['-','-','-.','-.',':',':']
  140. elif style == 'ls10':
  141. return ['-', '--', ':', '-.','-','--',':','-.','-','--']
  142. elif style =='lsa8':
  143. return ['-','--','-','--','-','--','-','--']
  144. elif style == 'lp8':
  145. return ['-',':','-',':','-',':','-',':']
  146. elif style == 'llt10':
  147. return ['-','--','-','--','-','--','-','--','-','--']
  148. elif style == 'lp10':
  149. return ['-',':','-',':','-',':','-',':','-',':']
  150. elif style == 'ldash':
  151. return [(0, ()),(0, (1, 10)),(0, (1, 5)),(0, (1, 1))]
  152. elif style == 'ls8':
  153. return [(0, ()),(0, (1, 1)),(0, (5, 10)),(0, (5, 5)),(0, (5, 1)),(0, (3, 10, 1, 10)),(0, (3, 5, 1, 5)),(0, (3, 5, 1, 5, 1, 5)) ]
  154. elif style == 'ln':
  155. return ["--", (0,(5,2,5,5,1,4))]
  156. elif style == 'paper':
  157. return [(0, ()), (0, (3, 1, 1, 1, 1, 1)), (0, (5, 5)),(0, (5, 1)),(0, (3, 5, 1, 5)),(0, (3, 5, 1, 5, 1, 5)),(0, (1, 1)),(0, (5, 10)) ]
  158. # linestyle = OrderedDict(
  159. # [('solid', (0, ())),
  160. # ('loosely dotted', (0, (1, 10))),
  161. # ('dotted', (0, (1, 5))),
  162. # ('densely dotted', (0, (1, 1))),
  163. # ('loosely dashed', (0, (5, 10))),
  164. # ('dashed', (0, (5, 5))),
  165. # ('densely dashed', (0, (5, 1))),
  166. # ('loosely dashdotted', (0, (3, 10, 1, 10))),
  167. # ('dashdotted', (0, (3, 5, 1, 5))),
  168. # ('densely dashdotted', (0, (3, 1, 1, 1))),
  169. # ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
  170. # ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
  171. # ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))])
  172. #----------------------------------------------------------------------------------------------------
  173. def cycle(self,n : str):
  174. if n == '0':
  175. return plt.cycler("color", self.schemes(self.parameters['scheme']) ) #colors)
  176. elif n=='1':
  177. return plt.cycler("color", self.schemes(self.parameters['scheme']) ) + plt.cycler("linestyle", self.linestyles(self.parameters['linestyle']))
  178. elif n=='2':
  179. return plt.cycler("color", self.schemes(self.parameters['scheme']) ) * plt.cycler("linestyle", self.linestyles(self.parameters['linestyle']))
  180. elif n=='3':
  181. return plt.cycler("linestyle", self.linestyles(self.parameters['linestyle'])) * plt.cycler("color", self.schemes(self.parameters['scheme']))
  182. else :
  183. raise ValueError('Index out of bound')
  184. #------------------------------------------------------------------------------------------------
  185. def setparams(self):
  186. #self.parameters.update(kwargs)
  187. if 'box' not in self.parameters.keys() :
  188. self.parameters['box'] = '#AAAAAA'
  189. if 'axeslabel' not in self.parameters.keys() :
  190. self.parameters['axeslabel'] = 'gray'
  191. if 'xtickcolor' not in self.parameters.keys() :
  192. self.parameters['xtickcolor'] = 'gray'
  193. if 'ytickcolor' not in self.parameters.keys() :
  194. self.parameters['ytickcolor'] = 'gray'
  195. if 'gridcolor' not in self.parameters.keys():
  196. self.parameters['gridcolor'] = '#dddddd'
  197. if 'font' not in self.parameters.keys():
  198. self.parameters['font'] = 'serif'
  199. if 'fontstyle' not in self.parameters.keys():
  200. self.parameters['fontstyle'] = 'italic'
  201. if 'text' not in self.parameters.keys():
  202. self.parameters['text'] = False
  203. if 'fontsize' not in self.parameters.keys():
  204. self.parameters['fontsize'] = 10.0
  205. if 'legendfontsize' not in self.parameters.keys():
  206. self.parameters['legendfontsize'] =10.0
  207. if 'legendEdgeColor' not in self.parameters.keys():
  208. self.parameters['legendEdgeColor'] = '#dddddd'
  209. if 'labelsize' not in self.parameters.keys():
  210. self.parameters['labelsize'] = [12,12,12]
  211. if 'linestyle' not in self.parameters.keys():
  212. self.parameters['linestyle'] = self.linestyles('paper')
  213. if 'scheme' not in self.parameters.keys():
  214. self.parameters['scheme'] = 'nb'
  215. if 'cycle' not in self.parameters.keys():
  216. self.parameters['cycle'] = self.cycle('0')
  217. if 'legend.loc' not in self.parameters.keys():
  218. self.parameters['legend.loc'] = 'best'
  219. if 'lines.linewidth' not in self.parameters.keys():
  220. self.parameters['lines.linewidth'] = '2'
  221. if 'grid.alpha' not in self.parameters.keys():
  222. self.parameters['grid.alpha'] = '1'
  223. if 'text.color' not in self.parameters.keys():
  224. self.parameters['text.color'] = 'gray'
  225. if 'font.sans-serif' not in self.parameters.keys():
  226. self.parameters['font.sans-serif'] = 'serif'
  227. if 'figure.figsize' not in self.parameters.keys():
  228. self.parameters['figure.figsize'] = [9.5,4.5]
  229. if 'subplot.bottom' not in self.parameters.keys():
  230. self.parameters['subplot.bottom'] = 0.125
  231. if 'text' not in self.parameters.keys():
  232. self.parameters['text'] = False
  233. if 'package' not in self.parameters.keys():
  234. self.parameters['package'] = []
  235. if 'grid.linewidth' not in self.parameters.keys():
  236. self.parameters['grid.linewidth'] = 1
  237. if 'axes.linewidth' not in self.parameters.keys():
  238. self.parameters['axes.linewidth'] = 0.7
  239. if 'font.weight' not in self.parameters.keys():
  240. self.parameters['font.weight'] = 'normal'
  241. if 'legend.borderpad' not in self.parameters.keys():
  242. self.parameters['legend.borderpad'] = 0.5
  243. if 'legend.borderaxespad' not in self.parameters.keys():
  244. self.parameters['legend.borderaxespad'] =0.5
  245. if 'legend.framelinewidth' not in self.parameters.keys():
  246. self.parameters['legend.framelinewidth'] = 1.0
  247. if 'boxplot.boxprops.linestyle' not in self.parameters.keys():
  248. self.parameters['boxplot.boxprops.linestyle'] = '--'
  249. if 'tick.MajW' not in self.parameters.keys():
  250. self.parameters['tick.MajW'] = 0.7
  251. if 'tick.minW' not in self.parameters.keys():
  252. self.parameters['tick.minW'] = 0.7
  253. myparams = {
  254. 'patch.linewidth' : '0.5',
  255. 'patch.facecolor' : '#348ABD', # blue
  256. 'patch.edgecolor' : 'EEEEEE',
  257. 'patch.antialiased' : True,
  258. 'font.size': self.parameters['fontsize'],
  259. 'xtick.major.size' : 0.1,
  260. 'xtick.minor.size' : 0.025,
  261. 'axes.edgecolor': self.parameters['box'] ,
  262. 'axes.linewidth': self.parameters['axes.linewidth'], # BOX width
  263. 'axes.xmargin': 0,
  264. 'axes.ymargin': 0,
  265. 'axes.labelcolor': self.parameters['axeslabel'],
  266. 'axes.axisbelow': True,
  267. 'xtick.color': self.parameters['xtickcolor'],
  268. 'ytick.color': self.parameters['ytickcolor'],
  269. 'axes.prop_cycle': self.parameters['cycle'],
  270. 'grid.linestyle': '--',
  271. 'grid.alpha': self.parameters['grid.alpha'],
  272. 'grid.linewidth' : self.parameters['grid.linewidth'],
  273. 'grid.color' : self.parameters['gridcolor'],
  274. 'font.family': self.parameters['font'] ,
  275. #'labelsize' : self.parameters['labelsize'],
  276. 'font.size' : self.parameters['fontsize'],
  277. 'legend.edgecolor' : self.parameters['legendEdgeColor'],
  278. 'legend.fancybox' : False,
  279. 'legend.borderpad' : self.parameters['legend.borderpad'],
  280. 'legend.fontsize' : self.parameters['legendfontsize'],
  281. 'legend.loc' : self.parameters['legend.loc'] ,
  282. 'legend.framealpha': 1,
  283. 'legend.borderaxespad' : self.parameters['legend.borderaxespad'],
  284. 'lines.linewidth' : self.parameters['lines.linewidth'],
  285. 'font.style' : self.parameters['fontstyle'],
  286. 'figure.autolayout': False,
  287. 'font.sans-serif' : self.parameters['font.sans-serif'],
  288. 'text.usetex': self.parameters['text'] ,
  289. 'patch.linewidth' : self.parameters['legend.framelinewidth'],
  290. 'boxplot.boxprops.linestyle' : self.parameters['boxplot.boxprops.linestyle'],
  291. #'figure.dpi': 72.0,
  292. #'figure.edgecolor': (1, 1, 1, 0),
  293. #'figure.facecolor': (1, 1, 1, 0),
  294. 'figure.figsize': self.parameters['figure.figsize'], #[6.0, 4.0],
  295. #'figure.frameon': True,
  296. #'figure.max_open_warning': 20,
  297. 'figure.subplot.bottom': self.parameters['subplot.bottom'], #0.125,
  298. 'figure.subplot.hspace': 0.2,
  299. 'figure.subplot.left': 0.125,
  300. 'figure.subplot.right': 0.9,
  301. 'figure.subplot.top': 0.9,
  302. 'figure.subplot.wspace': 0.2,
  303. 'figure.titlesize': 'large',
  304. 'figure.titleweight': 'normal',
  305. 'text.color' : self.parameters['text.color'],
  306. #'axes.axisbelow': False,
  307. #'axes.edgecolor': 'k',
  308. #'axes.facecolor': 'w',
  309. #'axes.formatter.limits': [-7, 7],
  310. #'axes.formatter.use_locale': False,
  311. #'axes.formatter.use_mathtext': False,
  312. #'axes.formatter.useoffset': True,
  313. #'axes.grid': False,
  314. 'axes.grid.axis': 'both',
  315. #'axes.grid.which': 'major',
  316. #'axes.hold': True,
  317. #'axes.labelcolor': 'k',
  318. #'axes.labelpad': 5.0,
  319. 'axes.labelsize': 'large',
  320. #'axes.labelweight': 'normal',
  321. #'axes.linewidth': 1.0,
  322. #'axes.prop_cycle': cycler('color', ['b', 'g', 'r', 'c', 'm', 'y', 'k']),
  323. #'axes.spines.bottom': True,
  324. #'axes.spines.left': True,
  325. #'axes.spines.right': True,
  326. #'axes.spines.top': True,
  327. 'axes.titlesize': 'large',
  328. #'axes.titleweight': 'normal',
  329. #'axes.unicode_minus': True,
  330. #'axes.xmargin': 0.0,
  331. #'axes.ymargin': 0.0,
  332. #font.family : sans-serif
  333. #font.style : normal
  334. #font.variant : normal
  335. 'font.weight' : self.parameters['font.weight'],
  336. #font.stretch : normal
  337. # 'font.cursive': ['Apple Chancery',
  338. # 'Textile',
  339. # 'Zapf Chancery',
  340. # 'Sand',
  341. # 'Script MT',
  342. # 'Felipa',
  343. # 'cursive'],
  344. # 'font.family': ['sans-serif'],
  345. # 'font.fantasy': ['Comic Sans MS',
  346. # 'Chicago',
  347. # 'Charcoal',
  348. # 'ImpactWestern',
  349. # 'Humor Sans',
  350. # 'fantasy'],
  351. # 'font.monospace': ['Bitstream Vera Sans Mono',
  352. # 'DejaVu Sans Mono',
  353. # 'Andale Mono',
  354. # 'Nimbus Mono L',
  355. # 'Courier New',
  356. # 'Courier',
  357. # 'Fixed',
  358. # 'Terminal',
  359. # 'monospace'],
  360. # 'font.sans-serif': ['Bitstream Vera Sans',
  361. # 'DejaVu Sans',
  362. # 'Lucida Grande',
  363. # 'Verdana',
  364. # 'Geneva',
  365. # 'Lucid',
  366. # 'Arial',
  367. # 'Helvetica',
  368. # 'Avant Garde',
  369. # 'sans-serif'],
  370. # 'font.serif': ['Bitstream Vera Serif',
  371. # 'DejaVu Serif',
  372. # 'New Century Schoolbook',
  373. # 'Century Schoolbook L',
  374. # 'Utopia',
  375. # 'ITC Bookman',
  376. # 'Bookman',
  377. # 'Nimbus Roman No9 L',
  378. # 'Times New Roman',
  379. # 'Times',
  380. # 'Palatino',
  381. # 'Charter',
  382. # 'serif'],
  383. # 'font.size': 10.0,
  384. # 'text.antialiased': True,
  385. # 'text.color': 'k',
  386. # 'text.dvipnghack': None,
  387. # 'text.hinting': 'auto',
  388. # 'text.hinting_factor': 8,
  389. 'text.latex.preamble': self.parameters['package'],
  390. # 'text.latex.preview': False,
  391. # 'text.latex.unicode': False,
  392. #
  393. #
  394. # 'xtick.color': 'k',
  395. # 'xtick.direction': 'in',
  396. # 'xtick.labelsize': 'medium',
  397. # 'xtick.major.pad': 4.0,
  398. # 'xtick.major.size': 4.0,
  399. # 'xtick.major.width': 1.5,
  400. # 'xtick.minor.pad': 4.0,
  401. # 'xtick.minor.size': 2.0,
  402. # 'xtick.minor.visible': False,
  403. # 'xtick.minor.width': 0.5,
  404. # 'ytick.color': 'k',
  405. # 'ytick.direction': 'in',
  406. # 'ytick.labelsize': 'medium',
  407. # 'ytick.major.pad': 4.0,
  408. # 'ytick.major.size': 4.0,
  409. # 'ytick.major.width': 1.5
  410. # 'ytick.minor.pad': 4.0,
  411. # 'ytick.minor.size': 2.0,
  412. # 'ytick.minor.visible': False,
  413. # 'ytick.minor.width': 0.5
  414. }
  415. # if self.parameters['text']:
  416. # plt.rc('text', usetex=True )
  417. # plt.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
  418. # plt.rc('font',family='' ,size=14 )
  419. #
  420. # if 'package' in self.parameters.keys():
  421. # for i in self.parameters['package']:
  422. # string = r"\usepackage{" + i + "}"
  423. # plt.rcParams['text.latex.preamble']=[string]
  424. ###########################################
  425. plt.rcParams.update(myparams)
  426. ###########################################
  427. #----------------------------------------------------------------------------------------------------------
  428. def set(self, nrows, ncols, fig , axs, kwargs):
  429. self.config = kwargs
  430. #print(self.config)
  431. if 'grid.linestyle' not in self.config.keys():
  432. self.config['grid.linestyle'] = '--'
  433. if 'grid.dashes' not in self.config.keys():
  434. self.config['grid.dashes'] = (5,7)
  435. if 'title.colors' not in self.config.keys():
  436. self.config['title.colors'] = '#555555'
  437. if 'subplot.bottom' not in self.config.keys():
  438. self.config['subplot.bottom'] = 0.125
  439. if 'subplot.right' not in self.config.keys():
  440. self.config['right.bottom'] = 0.93
  441. if 'legend.bbox' not in self.config.keys():
  442. self.config['legend.bbox'] = (0,0)
  443. if 'legend.loc' not in self.config.keys():
  444. self.config['legend.loc'] = 'best'
  445. if 'figure.figuresize' not in self.config.keys():
  446. self.config['figure.figuresize'] = [8,5.5]
  447. if 'legend.axespad' not in self.config.keys():
  448. self.config['legend.axespad'] = 0.
  449. if 'legend.framelinewidth' not in self.config.keys():
  450. self.config['legend.framelinewidth'] = 0.2
  451. if 'legend.textcolor' not in self.config.keys():
  452. self.config['legend.textcolor'] = '#555555'
  453. #self.config['legend.axespad'] = 0.
  454. for i in range(nrows):
  455. for j in range(ncols):
  456. #self.axs[i,j].set_xlim( self.findLimits()[0] , self.findLimits()[1] )
  457. #self.axs[i,j].set_ylim( self.findLimits()[2] , self.findLimits()[3] + 0.02 )
  458. minorLocator = AutoMinorLocator(4)
  459. majorLocator = MultipleLocator(10)
  460. majorFormatter = FormatStrFormatter('%f')
  461. if nrows == ncols == 1:
  462. self.axs.grid(linestyle= self.config['grid.linestyle'] , dashes= self.config['grid.dashes'])
  463. self.axs.set_title('', color=self.config['title.colors'] )
  464. self.axs.xaxis.set_minor_locator(AutoMinorLocator(5))
  465. self.axs.yaxis.set_minor_locator(AutoMinorLocator(5))
  466. self.axs.yaxis.set_ticks_position('both')
  467. self.axs.xaxis.set_ticks_position('both')
  468. self.axs.tick_params(which='major', width=self.config['tick.MajW']) # 1
  469. self.axs.tick_params(which='major', length=5.5)
  470. self.axs.tick_params(which='minor', width=self.config['tick.minW'])
  471. self.axs.tick_params(which='minor', length=3)
  472. legend = leg = self.axs.legend()
  473. #self.axs.legend( bbox_to_anchor=self.config['legend.bbox'] , loc= self.config['legend.bbox'] )
  474. legend.get_frame().set_linewidth(self.config['legend.framelinewidth'])
  475. #legend.get_frame().set_linewidth(0.1)
  476. #legend.get_frame().set_ linewidth(0.1)
  477. plt.setp(legend.get_texts(), color=self.config['legend.textcolor'] )
  478. elif nrows == 1 or ncols==1 :
  479. self.axs[i].grid(linestyle= self.config['grid.linestyle'] , dashes= self.config['grid.dashes'])
  480. self.axs[i].set_title('', color='#555555')
  481. self.axs[i].xaxis.set_minor_locator(AutoMinorLocator(5))
  482. self.axs[i].yaxis.set_minor_locator(AutoMinorLocator(5))
  483. self.axs[i].yaxis.set_ticks_position('both')
  484. self.axs[i].xaxis.set_ticks_position('both')
  485. # self.axs[i].tick_params(which='major', width=0.5)
  486. self.axs[i].tick_params(which='major', width=self.config['tick.MajW']) # 1
  487. self.axs[i].tick_params(which='major', length=5)
  488. self.axs[i].tick_params(which='minor', width=self.config['tick.minW'])
  489. self.axs[i].tick_params(which='minor', length=2.5)
  490. legend = leg = self.axs[i].legend()
  491. legend.get_frame().set_linewidth(0.5)
  492. plt.setp(legend.get_texts(), color=self.config['legend.textcolor'])
  493. else :
  494. self.axs[i,j].grid(linestyle= self.config['grid.linestyle'] , dashes= self.config['grid.dashes'])
  495. self.axs[i,j].set_title('', color='#555555')
  496. self.axs[i,j].xaxis.set_minor_locator(AutoMinorLocator(5))
  497. self.axs[i,j].yaxis.set_minor_locator(AutoMinorLocator(5))
  498. self.axs[i,j].yaxis.set_ticks_position('both')
  499. self.axs[i,j].xaxis.set_ticks_position('both')
  500. # self.axs[i,j].tick_params(which='major', width=0.5)
  501. self.axs[i,j].tick_params(which='major', width=self.config['tick.MajW']) # 1
  502. self.axs[i,j].tick_params(which='major', length=5)
  503. self.axs[i,j].tick_params(which='minor', width=self.config['tick.minW'])
  504. self.axs[i,j].tick_params(which='minor', length=2.5)
  505. #linestyles = ["--","-.",":", (0,(5,2,1,4))]
  506. # linestyles = [(0,(7,7)),(0,(7,7)),(0,(7,7)), (0,(7,7))]
  507. # for ax, ls in zip(axs.flat, linestyles):
  508. # for spine in ax.spines.values():
  509. # spine.set_linestyle(ls)
  510. legend = leg = self.axs[i,j].legend()
  511. #legend.get_frame().set_linewidth(self.config['legend.framelinewidth'])
  512. legend.get_frame().set_linewidth(0.5)
  513. plt.setp(legend.get_texts(), color=self.config['legend.textcolor'])
  514. #axs.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
  515. ##plt.title(y=1.25)
  516. #### plt.legend([l1, l2, l3],["HHZ 1", "HHN", "HHE"])
  517. if nrows == ncols ==1 :
  518. self.config['subplot.bottom'] = 0.175
  519. self.config['subplot.right'] = 0.93
  520. plt.subplots_adjust(left=0.125 , bottom=self.config['subplot.bottom'], right=self.config['subplot.right'], top=0.87, wspace=0, hspace=0)
  521. else:
  522. plt.subplots_adjust(left=0.06 , bottom=0.1, right=0.95, top=0.93, wspace=0.2, hspace=0.6) # 0.2 , 0.4
  523. return self.fig,self.axs
  524. def __call__ (self,nrows,ncols,figsize=(9.5,4.5)):
  525. self.nrows = nrows
  526. self.ncols = ncols
  527. self.figsize = figsize
  528. self.parameters['figure.figsize'] = self.figsize
  529. self.setparams()
  530. if self.nrows == self.ncols ==1:
  531. self.fig, self.axs = plt.subplots( self.nrows, self.ncols,figsize=self.figsize)
  532. else:
  533. self.fig, self.axs = plt.subplots( self.nrows, self.ncols,figsize=self.figsize)
  534. self.fig,self.axs = self.set( self.nrows, self.ncols,self.fig,self.axs, self.parameters )
  535. return self.fig,self.axs
  536. # left = 0.125 # the left side of the subplots of the figure
  537. # right = 0.9 # the right side of the subplots of the figure
  538. # bottom = 0.1 # the bottom of the subplots of the figure
  539. # top = 0.9 # the top of the subplots of the figure
  540. # wspace = 0.2 # the amount of width reserved for space between subplots,
  541. # # expressed as a fraction of the average axis width
  542. # hspace = 0.2 # the amount of height reserved for space between subplots,
  543. # # expressed as a fraction of the average axis height
  544. #
  545. #------------------------------------------------------------------------------------------------
  546.