Skip to content

Commit a3293b7

Browse files
committed
New field.timelabel switch
It adds a label with the time of the snapshot on field figures.
1 parent ed34e83 commit a3293b7

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

stagpy/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _index_collection(arg):
103103
'plot departure from average profile')),
104104
('shift', Conf(None, True, None, {'type': int},
105105
False, 'Shift plot horizontally')),
106+
('timelabel', switch_opt(False, None, 'add label with time')),
106107
('interpolate', switch_opt(True, None, 'apply Gouraud shading')),
107108
('colorbar', switch_opt(True, None, 'add color bar to plot')),
108109
('ix', Conf(None, True, None, {'type': int},

stagpy/field.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def plot_scalar(step, var, field=None, axis=None, **extra):
209209
axis.set_axis_off()
210210
else:
211211
axis.set_aspect(conf.plot.ratio / axis.get_data_ratio())
212+
212213
axis.set_adjustable('box')
213214
axis.set_xlim(xmin, xmax)
214215
axis.set_ylim(ymin, ymax)
@@ -290,7 +291,7 @@ def cmd():
290291
for step in sdat.walk.filter(snap=True):
291292
for vfig in lovs:
292293
fig, axes = plt.subplots(ncols=len(vfig), squeeze=False,
293-
figsize=(12 * len(vfig), 9))
294+
figsize=(9 * len(vfig), 6))
294295
for axis, var in zip(axes[0], vfig):
295296
if var[0] not in step.fields:
296297
print("'{}' field on snap {} not found".format(var[0],
@@ -305,6 +306,11 @@ def cmd():
305306
plot_iso(axis, step, var[1])
306307
elif valid_field_var(var[1] + '1'):
307308
plot_vec(axis, step, var[1])
309+
if conf.field.timelabel:
310+
time, unit = sdat.scale(step.timeinfo['t'], 's')
311+
time = misc.scilabel(time)
312+
axes[0, 0].text(0.02, 1.02, '$t={}$ {}'.format(time, unit),
313+
transform=axes[0, 0].transAxes)
308314
oname = '_'.join(chain.from_iterable(vfig))
309315
plt.tight_layout(w_pad=3)
310316
misc.saveplot(fig, oname, step.isnap)

stagpy/misc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ def out_name(stem, timestep=None):
3333
return conf.core.outname + '_' + stem
3434

3535

36+
def scilabel(value, precision=2):
37+
"""Build scientific notation of some value.
38+
39+
This is dedicated to use in labels displaying scientific values.
40+
41+
Args:
42+
value (float): numeric value to format.
43+
precision (int): number of decimal digits.
44+
45+
Returns:
46+
str: the scientific notation the specified value.
47+
"""
48+
fmt = '{{:.{}e}}'.format(precision)
49+
man, exp = fmt.format(value).split('e')
50+
exp = int(exp)
51+
return r'{}\times 10^{{{}}}'.format(man, exp)
52+
53+
3654
def saveplot(fig, *name_args, close=True, **name_kwargs):
3755
"""Save matplotlib figure.
3856

0 commit comments

Comments
 (0)