Skip to content

Commit e4dd4fd

Browse files
committed
beautification for TOMS
1 parent 7cd3928 commit e4dd4fd

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

pySDC/helpers/plot_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def setup_mpl(font_size=8):
4545
r"\usepackage[utf8x]{inputenc}", # use utf8 fonts becasue your computer can handle it :)
4646
r"\usepackage[T1]{fontenc}", # plots will be generated using this preamble
4747
r"\usepackage{underscore}",
48+
r"\usepackage{amsmath,amssymb,marvosym}"
4849
]
4950
}
5051
mpl.rcParams.update(pgf_with_latex)

pySDC/projects/TOMS/visualize_pySDC_with_PETSc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ def visualize_matrix(result=None):
9494
tmax = max(tmax, item)
9595

9696
plt_helper.setup_mpl()
97-
plt_helper.newfig(textwidth=238.96, scale=1.33)
98-
97+
plt_helper.newfig(textwidth=120, scale=1.5)
9998
cmap = plt_helper.plt.get_cmap('RdYlGn_r')
10099
new_cmap = truncate_colormap(cmap, 0.1, 0.9)
101-
plt_helper.plt.imshow(mat, origin='lower', norm=colors.LogNorm(vmin=tmin, vmax=tmax), cmap=new_cmap)
100+
plt_helper.plt.imshow(mat, origin='lower', norm=colors.LogNorm(vmin=tmin, vmax=tmax), cmap=new_cmap, aspect='auto')
102101

103102
for key, item in result.items():
104103
timing = "{:3.1f}".format(item)
105-
plt_helper.plt.text(process_list.index(key[0]), process_list.index(key[1]), timing, ha='center', va='center')
104+
plt_helper.plt.annotate(timing, xy=(process_list.index(key[0]), process_list.index(key[1])), size='x-small',
105+
ha='center', va='center')
106106

107107
plt_helper.plt.xticks(range(dim), process_list)
108108
plt_helper.plt.yticks(range(dim), process_list)
@@ -136,7 +136,7 @@ def visualize_speedup(result=None):
136136
timing_PFASST[process_list_PFASST.index(key[0] * key[1])] = item
137137

138138
plt_helper.setup_mpl()
139-
plt_helper.newfig(textwidth=238.96, scale=1.33)
139+
plt_helper.newfig(textwidth=120, scale=1.5)
140140

141141
process_list_all = process_list_MLSDC + process_list_PFASST
142142
ideal = [timing_MLSDC[0] / nproc for nproc in process_list_all]

pySDC/projects/node_failure/postproc_grayscott.py

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 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+
46
from pylab import rcParams
57

68
axis_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

149154
if __name__ == "__main__":

0 commit comments

Comments
 (0)