Skip to content

Commit 4cb894f

Browse files
committed
Interpolate fields to cell centers in plot_scalar
This avoids matplotlib >= 3.5 erroring out because dimensions are inconsistent when plotting a velocity field (that has an extra point along the horizontal axis.
1 parent 23a90d5 commit 4cb894f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stagpy/field.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,13 @@ def plot_scalar(step, var, field=None, axis=None, **extra):
168168

169169
xmesh, ymesh, fld, meta = get_meshes_fld(step, var,
170170
walls=not conf.field.interpolate)
171+
# interpolate at cell centers, this should be abstracted by field objects
172+
# via an "at_cell_centers" method or similar
173+
if fld.shape[0] > max(step.geom.nxtot, step.geom.nytot):
174+
fld = (fld[:-1] + fld[1:]) / 2
175+
171176
if conf.field.interpolate and \
172-
step.geom.spherical and step.geom.twod_yz and \
173-
fld.shape[0] == step.geom.nytot:
177+
step.geom.spherical and step.geom.twod_yz:
174178
# add one point to close spherical annulus
175179
xmesh = np.concatenate((xmesh, xmesh[:1]), axis=0)
176180
ymesh = np.concatenate((ymesh, ymesh[:1]), axis=0)

0 commit comments

Comments
 (0)