Skip to content

Commit 6e626b2

Browse files
committed
plot_iso learns kwargs, field.(isocolors|cmap)
Similarly to plot_scalar, plot_iso now passes additional kwargs to the underlying matplotlib function. Moreover, isolines are now colored with the relevant field.cmap or field.isocolors instead if specified.
1 parent 90639b1 commit 6e626b2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stagpy/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def _index_collection(arg):
112112
False, 'y-index of slice for 3D fields')),
113113
('iz', Conf(None, True, None, {'type': int},
114114
False, 'z-index of slice for 3D fields')),
115+
('isocolors', Conf('', True, None, {}, True,
116+
'comma-separated list of colors for isolines')),
115117
('cmap',
116118
Conf({'T': 'RdBu_r',
117119
'eta': 'viridis_r',

stagpy/field.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def plot_scalar(step, var, field=None, axis=None, **extra):
216216
return fig, axis, surf, cbar
217217

218218

219-
def plot_iso(axis, step, var):
219+
def plot_iso(axis, step, var, **extra):
220220
"""Plot isocontours of scalar field.
221221
222222
Args:
@@ -226,11 +226,19 @@ def plot_iso(axis, step, var):
226226
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
227227
instance.
228228
var (str): the scalar field name.
229+
extra (dict): options that will be passed on to
230+
:func:`matplotlib.axes.Axes.contour`.
229231
"""
230232
xmesh, ymesh, fld = get_meshes_fld(step, var)
231233
if conf.field.shift:
232234
fld = np.roll(fld, conf.field.shift, axis=0)
233-
axis.contour(xmesh, ymesh, fld, linewidths=1)
235+
extra_opts = dict(linewidths=1)
236+
if 'cmap' not in extra and conf.field.isocolors:
237+
extra_opts['colors'] = conf.field.isocolors.split(',')
238+
elif 'colors' not in extra:
239+
extra_opts['cmap'] = conf.field.cmap.get(var)
240+
extra_opts.update(extra)
241+
axis.contour(xmesh, ymesh, fld, **extra_opts)
234242

235243

236244
def plot_vec(axis, step, var):

0 commit comments

Comments
 (0)