11import numpy as np
2- # import os
3- import matplotlib .pyplot as plt
2+ import os
3+
4+ import pySDC .helpers .plot_helper as plt_helper
5+
46from pylab import rcParams
57
68axis_font = {'fontname' : 'Arial' , 'size' : '8' , 'family' : 'serif' }
@@ -43,6 +45,7 @@ def create_plots(cwd=''):
4345 nsteps = 0
4446 maxiter = 0
4547 vmax = - 99
48+ vmin = 99
4649 for file , strategy , label , color , marker in list :
4750 data = np .load (cwd + 'data/' + file )
4851
@@ -60,10 +63,11 @@ def create_plots(cwd=''):
6063 data = np .load (cwd + 'data/' + ref )
6164 ref_iter_count = data ['iter_count' ][nprocs - 1 ::nprocs ]
6265
63- rcParams ['figure.figsize' ] = 6.0 , 2.5
64- fig , ax = plt .subplots ()
66+ plt_helper .setup_mpl ()
67+
68+ fig , ax = plt_helper .newfig (textwidth = 238.96 , scale = 2.0 , ratio = 0.3 )
6569
66- plt .plot (range (nblocks ), [0 ] * nblocks , 'k-' , linewidth = 2 )
70+ ax .plot (range (nblocks ), [0 ] * nblocks , 'k-' , linewidth = 2 )
6771
6872 ymin = 99
6973 ymax = 0
@@ -76,23 +80,24 @@ def create_plots(cwd=''):
7680 ymin = min (ymin , min (iter_count - ref_iter_count ))
7781 ymax = max (ymax , max (iter_count - ref_iter_count ))
7882
79- plt .plot (range (nblocks ), iter_count - ref_iter_count , color = color , label = label , marker = marker , linestyle = '' ,
80- linewidth = lw , markersize = ms )
83+ ax .plot (range (nblocks ), iter_count - ref_iter_count , color = color , label = label , marker = marker , linestyle = '' ,
84+ linewidth = lw , markersize = ms )
8185
82- plt .xlabel ('block' , ** axis_font )
83- plt .ylabel ('$K_\\ mathrm{add}$' , ** axis_font )
84- plt .title ('ALL' )
85- plt .xlim (- 1 , nblocks )
86- plt .ylim (- 1 + ymin , ymax + 1 )
87- plt .legend (loc = 2 , numpoints = 1 , fontsize = fs )
88- plt .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
89- ax .xaxis .labelpad = - 0.5
90- ax .yaxis .labelpad = - 1
91- # plt.tight_layout()
86+ ax .set_xlabel ('block' )
87+ ax .set_ylabel (r'$K_\mathrm{add}$' )
88+ # ax.set_title('ALL')
89+ ax .set_xlim (- 1 , nblocks )
90+ ax .set_ylim (- 1 + ymin , ymax + 1 )
91+ ax .legend (loc = 2 , numpoints = 1 , fontsize = fs )
92+ ax .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
9293
93- fname = 'data/GRAYSCOTT_Kadd_vs_NOFAULT_hf.png'
94- plt .savefig (fname , bbox_inches = 'tight' , rasterize = True )
95- # os.system('pdfcrop ' + fname + ' ' + fname)
94+ # save plot, beautify
95+ fname = 'data/GRAYSCOTT_Kadd_vs_NOFAULT_hf'
96+ plt_helper .savefig (fname )
97+
98+ assert os .path .isfile (fname + '.pdf' ), 'ERROR: plotting did not create PDF file'
99+ assert os .path .isfile (fname + '.pgf' ), 'ERROR: plotting did not create PGF file'
100+ assert os .path .isfile (fname + '.png' ), 'ERROR: plotting did not create PNG file'
96101
97102 for file , strategy , label , color , marker in list :
98103
@@ -104,46 +109,46 @@ def create_plots(cwd=''):
104109 residual [residual <= 0 ] = 1E-99
105110 residual = np .log10 (residual )
106111
107- rcParams ['figure.figsize' ] = 8.0 , 2.0
108- fig , ax = plt .subplots ()
112+ fig , ax = plt_helper .newfig (textwidth = 238.96 , scale = 2.0 , ratio = 0.3 )
109113
110- cmap = plt .get_cmap ('Reds' , vmax - vmin + 1 )
111- pcol = plt .pcolor (residual , cmap = cmap , vmin = vmin , vmax = vmax )
114+ cmap = plt_helper . plt .get_cmap ('Reds' , vmax - vmin + 1 )
115+ pcol = ax .pcolor (residual , cmap = cmap , vmin = vmin , vmax = vmax )
112116 pcol .set_edgecolor ('face' )
113117
114118 if file is not ref :
115119 for item in stats :
116120 if item [0 ] in range (minstep , maxstep ):
117- plt .text (item [0 ] + 0.5 - (maxstep - nsteps ), item [1 ] - 1 + 0.5 , 'x' , horizontalalignment = 'center ' ,
118- verticalalignment = 'center' )
121+ ax .text (item [0 ] + 0.5 - (maxstep - nsteps ), item [1 ] - 1 + 0.5 , r'\text{\Lightning} ' ,
122+ horizontalalignment = 'center' , verticalalignment = 'center' )
119123
120- plt .axis ([0 , nsteps , 0 , maxiter ])
124+ ax .axis ([0 , nsteps , 0 , maxiter - 1 ])
121125
122126 ticks = np .arange (vmin , vmax + 1 , 2 )
123127 tickpos = np .linspace (ticks [0 ] + 0.5 , ticks [- 1 ] - 0.5 , len (ticks ))
124- cax = plt .colorbar (pcol , ticks = tickpos , pad = 0.02 )
128+ cax = plt_helper . plt .colorbar (pcol , ticks = tickpos , pad = 0.02 )
125129 cax .set_ticklabels (ticks )
126130 cax .ax .tick_params (labelsize = fs )
127131
128- cax .set_label ('log10(residual)' , ** axis_font )
129- plt .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
130- ax .xaxis .labelpad = - 0.5
131- ax .yaxis .labelpad = - 0.5
132+ cax .set_label ('log10(residual)' )
133+ ax .tick_params (axis = 'both' , which = 'major' , labelsize = fs )
132134
133- ax .set_xlabel ('step' , ** axis_font )
134- ax .set_ylabel ('iteration' , ** axis_font )
135+ ax .set_xlabel ('step' )
136+ ax .set_ylabel ('iteration' )
135137
136138 ax .set_yticks (np .arange (1 , maxiter , 2 ) + 0.5 , minor = False )
137139 ax .set_xticks (np .arange (0 , nsteps , xtick_dist ) + 0.5 , minor = False )
138140 ax .set_yticklabels (np .arange (1 , maxiter , 2 ) + 1 , minor = False )
139141 ax .set_xticklabels (np .arange (minstep , maxstep , xtick_dist ), minor = False )
140142
141- plt .title (strategy .replace ('_' , '-' ))
143+ # plt.title(strategy.replace('_', '-'))
142144 # plt.tight_layout()
143145
144- fname = 'data/GRAYSCOTT_steps_vs_iteration_hf_' + strategy + '.png'
145- plt .savefig (fname , bbox_inches = 'tight' , rasterize = True )
146- # os.system('pdfcrop ' + fname + ' ' + fname)
146+ fname = 'data/GRAYSCOTT_steps_vs_iteration_hf_' + strategy
147+ plt_helper .savefig (fname )
148+
149+ assert os .path .isfile (fname + '.pdf' ), 'ERROR: plotting did not create PDF file'
150+ assert os .path .isfile (fname + '.pgf' ), 'ERROR: plotting did not create PGF file'
151+ assert os .path .isfile (fname + '.png' ), 'ERROR: plotting did not create PNG file'
147152
148153
149154if __name__ == "__main__" :
0 commit comments