plot-plasma-grid.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import numpy as np
  4. from matplotlib import patches
  5. from matplotlib.path import Path
  6. data = []
  7. r=115
  8. #r=100
  9. #r=75
  10. #name = "Fig3%s"%r
  11. #to_plot = {1,6,8}
  12. #to_plot = {0,1,2,3,4,5,6,7}
  13. #-80,-60,-30, -20, -10
  14. # to_plot = {"a","b","c","d",
  15. # "e","f","g","h",
  16. # "i","j","k","l"}
  17. to_plot = ["a","e","i",
  18. "b","f","j",
  19. "c","g","k",
  20. "d","h","l"]
  21. for i in range(len(to_plot)):
  22. #print(i, to_plot[i])
  23. data.append(
  24. np.transpose(
  25. np.loadtxt("Fig3%s.txt"%to_plot[i])
  26. )[-1]
  27. )
  28. space = 25
  29. px = 190-space
  30. for i in range(len(data)):
  31. dim = int(np.sqrt(len(data[i])))
  32. data[i] = np.reshape(data[i], (dim, dim) )
  33. zero = np.zeros((dim+2*space, dim+2*space))
  34. zero[space:-space, space:-space] = data[i]
  35. tmp = zero
  36. # Re(\epsilon) = 3.681^2 - 2.7* 10^{-21}*N_e(in cm^{-3}).
  37. #data[i] = 3.681**2 - 2.7*np.transpose(tmp)*5e22/1e21
  38. #data[i] = 3.681 - np.sqrt(3.681**2 - 2.7*np.transpose(tmp)*5e22/1e21)
  39. data[i] = -2.7*np.transpose(tmp)*5e22/1e21
  40. # if i == 0:
  41. # data[i] = np.transpose(tmp)*1000*5
  42. nm_scale = 2 # nm per pixel
  43. scale_x = np.linspace( -(250-px)*nm_scale, (250-px)*nm_scale, 500-2*px)
  44. scale_y = np.linspace( -(250-px)*nm_scale, (250-px)*nm_scale, 500-2*px)
  45. import matplotlib.pyplot as plt
  46. from matplotlib import rcParams
  47. from matplotlib import cm
  48. my_fontsize = 8
  49. rcParams.update({'font.size': my_fontsize})
  50. #rcParams.update({'mathtext.it': "TeX Gyre Termes Math"})
  51. import matplotlib
  52. # Match Overleaf template font for Nanoscale journal
  53. matplotlib.rcParams['mathtext.fontset'] = 'stix'
  54. # matplotlib.rcParams['mathtext.it'] = 'TeX Gyre Termes:italic'
  55. # matplotlib.rcParams['mathtext.fontset'] = 'custom'
  56. # matplotlib.rcParams['mathtext.rm'] = 'TeX Gyre Termes'
  57. # matplotlib.rcParams['mathtext.it'] = 'TeX Gyre Termes:italic'
  58. # matplotlib.rcParams['mathtext.bf'] = 'TeX Gyre Termes:bold'
  59. fig, axs = plt.subplots(3,4)#, sharey=True, sharex=True)
  60. axis_color = "white"
  61. #axis_color = "black"
  62. for i in range(len(data)):
  63. r=75
  64. if i%3==1: r=100
  65. if i%3==2: r=115
  66. if i//3 == 0:
  67. data[i] = data[i]*100
  68. print(r)
  69. # print(i%3, i//3)
  70. ax = axs[i%3][i//3]
  71. #max_tick = np.amax(data[i])*0.75
  72. max_tick = 0
  73. min_tick = np.amin(data[i])*0.65
  74. if i//3 == 0:
  75. min_tick = np.amin(data[i])*0.85
  76. if i//3 == 2:
  77. min_tick = np.amin(data[i])*0.55
  78. if i%3 == 2 and i//3 == 2:
  79. min_tick = np.amin(data[i])*0.29
  80. if max_tick > 10: max_tick = int(max_tick)
  81. if min_tick < -10: min_tick = int(min_tick)
  82. #if i!=0: max_tick = 1.3
  83. #min_tick = np.amin(data[i])
  84. #min_tick = 0.1
  85. #max_tick = 60
  86. scale_ticks = np.linspace(min_tick, max_tick, 2)
  87. cax = ax.imshow(data[i]
  88. #, interpolation='bicubic'
  89. , interpolation='none'
  90. #, cmap=cm.afmhot_r
  91. , cmap=cm.hot_r
  92. ,vmin=min_tick, vmax=max_tick
  93. , extent=(min(scale_x), max(scale_x), min(scale_y), max(scale_y))
  94. #, extent=(-50, 50, -50, 50)
  95. , aspect = 'equal'
  96. # ,norm = LogNorm()
  97. )
  98. # Define scale ticks
  99. # vertically oriented colorbar
  100. cbar = fig.colorbar(cax, ticks=[a for a in scale_ticks], ax=ax, fraction=0.042, pad=0.04)
  101. cbar.ax.set_yticklabels(['%2.1f' % (a) for a in scale_ticks], va="center", ha="left")
  102. if max_tick > 10 or min_tick <= -10:
  103. cbar.ax.set_yticklabels(['%i' % (int(a)) for a in scale_ticks], va="center", ha="left")
  104. #bar.ax.set_title(r'$n_e, 10^{22}{\rm cm}^{-3}$')
  105. lp_cbar = -5
  106. if max_tick > 10: lp_cbar = -1.5
  107. if max_tick > 100: lp_cbar = -4.7
  108. cbar.ax.set_ylabel(r'$\Delta \mathrm{Re}(\epsilon)$', labelpad = lp_cbar, fontsize=my_fontsize+1, rotation=90+180)
  109. if i//3 == 0:
  110. cbar.ax.set_ylabel(r'$\Delta \mathrm{Re}(\epsilon) \times 100$', labelpad = lp_cbar, fontsize=my_fontsize+1, rotation=90+180)
  111. #cbar.ax.set_ylabel(r'$n_e$', labelpad = lp_cbar, fontsize=my_fontsize+2, rotation=90+180)
  112. # cbar.ax.set_ylabel(r'$n_e,\; 10^{\,20} \ {\rm cm}^{-3}$', labelpad = -3, fontsize=my_fontsize+1, rotation=90+180)
  113. # cbar.ax.set_ylabel(r'$n_e,\; 10^{\;22}\ {\rm cm}^{-3}$', labelpad = -4, fontsize=my_fontsize+2, rotation=90+180)
  114. # if i == 0:
  115. # cbar.ax.set_ylabel(r'$n_e,\; 10^{\;19}\ {\rm cm}^{-3}$', labelpad = -4, fontsize=my_fontsize+2, rotation=90+180)
  116. #ax.set(adjustable='box-forced')
  117. # ax.xaxis.set_tick_params(width=outline_width/2.0)
  118. # ax.yaxis.set_tick_params(width=outline_width/2.0)
  119. # ax.tick_params(axis='x', colors=axis_color)
  120. # ax.tick_params(axis='y', colors=axis_color)
  121. ax.spines['bottom'].set_color(axis_color)
  122. ax.spines['top'].set_color(axis_color)
  123. ax.spines['right'].set_color(axis_color)
  124. ax.spines['left'].set_color(axis_color)
  125. ax.tick_params(axis='both', color=axis_color, width = 1.2)
  126. # for spine in ax.spines:
  127. # spine.set_color(axis_color)
  128. # ax.yaxis.label.set_color('red')
  129. lp1 = 1.0
  130. if r==115:
  131. ax.set_xlabel(r'$Z,\rm nm$', labelpad=lp1, fontsize=my_fontsize+2)
  132. else:
  133. ax.set_xticklabels([])
  134. ax.axis("image")
  135. s1 = patches.Arc((1., -1.), 2.0 * r, 2.0 * r, angle=0.0, zorder=1.8,
  136. theta1=0.0, theta2=360.0, linewidth=1.3,
  137. # color='white',
  138. color=axis_color,
  139. linestyle='--')
  140. # s1 = patches.Arc((2.5, -2.5), 2.0 * r, 2.0 * r, angle=0.0, zorder=1.8,
  141. # theta1=0.0, theta2=360.0, linewidth=0.7, color='white',
  142. # fill=False)
  143. ax.add_patch(s1)
  144. # axs[0][0].annotate('',
  145. # xy=(-0.45, 1.2), xycoords='axes fraction',
  146. # xytext=(-0.45, 0.9), textcoords='offset points',
  147. # size=10,
  148. # color="green",
  149. # # bbox=dict(boxstyle="round", fc="0.8"),
  150. # arrowprops=dict(arrowstyle="<->",
  151. # #fc="0.6", ec="none",
  152. # #patchB=el,
  153. # ))
  154. axs[0][0].annotate(r'${E}$', xy=(-0.48, 1.05), xycoords='axes fraction', fontsize=my_fontsize+4,
  155. horizontalalignment='center', verticalalignment='bottom', color="black")
  156. axs[0][0].annotate(s='', xy=(-0.38,1.24),
  157. xytext=(-0.38,0.84),
  158. size=12, xycoords='axes fraction',
  159. arrowprops=dict(arrowstyle='<->', linewidth=1.5))
  160. axs[0][0].annotate(r'${k}$', xy=(-0.2, 1.05), xycoords='axes fraction', fontsize=my_fontsize+4,
  161. horizontalalignment='center', verticalalignment='bottom', color="black")
  162. axs[0][0].annotate(s='', xy=(-0.36,1.04),
  163. xytext=(-0.04,1.04),
  164. size=12, xycoords='axes fraction',
  165. arrowprops=dict(arrowstyle='<-', linewidth=1.5))
  166. axs[0][0].annotate(r'$R=\rm 75\;nm$', xy=(-0.53, 0.5), xycoords='axes fraction', fontsize=my_fontsize+4,
  167. horizontalalignment='left', verticalalignment='center', color="black", rotation = 90)
  168. axs[1][0].annotate(r'$R=\rm 100\; nm$', xy=(-0.53, 0.5), xycoords='axes fraction', fontsize=my_fontsize+4,
  169. horizontalalignment='left', verticalalignment='center', color="black", rotation = 90)
  170. axs[2][0].annotate(r'$R=\rm 115\; nm$', xy=(-0.53, 0.5), xycoords='axes fraction', fontsize=my_fontsize+4,
  171. horizontalalignment='left', verticalalignment='center', color="black", rotation = 90)
  172. axs[0][0].annotate(r'$\rm Stage\;1$', xy=(0.5, 1.2), xycoords='axes fraction', fontsize=my_fontsize+4,
  173. horizontalalignment='center', verticalalignment='top', color="black")
  174. axs[0][1].annotate(r'$\rm Stage\;2$', xy=(0.5, 1.2), xycoords='axes fraction', fontsize=my_fontsize+4,
  175. horizontalalignment='center', verticalalignment='top', color="black")
  176. axs[0][2].annotate(r'$\rm Stage\;3$', xy=(0.5, 1.2), xycoords='axes fraction', fontsize=my_fontsize+4,
  177. horizontalalignment='center', verticalalignment='top', color="black")
  178. axs[0][3].annotate(r'$\rm Stage\;4$', xy=(0.5, 1.2), xycoords='axes fraction', fontsize=my_fontsize+4,
  179. horizontalalignment='center', verticalalignment='top', color="black")
  180. # axs[0][0].annotate(r'$\rm Stage 1$', xy=(0.5, -0.0), xycoords='axes fraction', fontsize=my_fontsize+4,
  181. # horizontalalignment='center', verticalalignment='top', color="white")
  182. if r: #r==75:
  183. axs[0][0].annotate('(a)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  184. horizontalalignment='left', verticalalignment='top', color=axis_color)
  185. axs[0][1].annotate('(b)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  186. horizontalalignment='left', verticalalignment='top', color=axis_color)
  187. axs[0][2].annotate('(c)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  188. horizontalalignment='left', verticalalignment='top', color=axis_color)
  189. axs[0][3].annotate('(d)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  190. horizontalalignment='left', verticalalignment='top', color=axis_color)
  191. if r: #r==100:
  192. axs[1][0].annotate('(e)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  193. horizontalalignment='left', verticalalignment='top', color=axis_color)
  194. axs[1][1].annotate('(f)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  195. horizontalalignment='left', verticalalignment='top', color=axis_color)
  196. axs[1][2].annotate('(g)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  197. horizontalalignment='left', verticalalignment='top', color=axis_color)
  198. axs[1][3].annotate('(h)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  199. horizontalalignment='left', verticalalignment='top', color=axis_color)
  200. if r: #r==115:
  201. axs[2][0].annotate('(i)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  202. horizontalalignment='left', verticalalignment='top', color=axis_color)
  203. axs[2][1].annotate('(j)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  204. horizontalalignment='left', verticalalignment='top', color=axis_color)
  205. axs[2][2].annotate('(k)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  206. horizontalalignment='left', verticalalignment='top', color=axis_color)
  207. axs[2][3].annotate('(l)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  208. horizontalalignment='left', verticalalignment='top', color=axis_color)
  209. # axs[2].annotate('(m)', xy=(0.045, 0.934), xycoords='axes fraction', fontsize=my_fontsize+2,
  210. # horizontalalignment='left', verticalalignment='top', color=axis_color)
  211. # axs[3].annotate('(n)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  212. # horizontalalignment='left', verticalalignment='top', color=axis_color)
  213. # axs[4].annotate('(o)', xy=(0.015, 0.96), xycoords='axes fraction', fontsize=my_fontsize+2,
  214. # horizontalalignment='left', verticalalignment='top', color=axis_color)
  215. lp2 = -10.0
  216. axs[0][0].set_ylabel(r'$X,\rm nm$', labelpad=lp2, fontsize=my_fontsize+2)
  217. axs[1][0].set_ylabel(r'$X,\rm nm$', labelpad=lp2, fontsize=my_fontsize+2)
  218. axs[2][0].set_ylabel(r'$X,\rm nm$', labelpad=lp2, fontsize=my_fontsize+2)
  219. for i in range(len(data)):
  220. print(i)
  221. ax = axs[i%3][i//3]
  222. if i//3 != 0:
  223. ax.set_yticklabels([])
  224. if i%3 != 2:
  225. ax.set_xticklabels([])
  226. ax.locator_params(axis='x',nbins=4)
  227. ax.locator_params(axis='y',nbins=4)
  228. fig.subplots_adjust(hspace=-0.43, wspace=0.25)
  229. #fig.tight_layout()
  230. plt.savefig("plasma-grid.pdf",pad_inches=0.02, bbox_inches='tight')
  231. plt.draw()
  232. # plt.show()
  233. plt.clf()
  234. plt.close()