Skip to content

Commit 76d8a4c

Browse files
committed
[bug] fix plot hold on bug
1 parent 515fec6 commit 76d8a4c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

iso2mesh/plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def plotsurf(node, face, *args, **kwargs):
127127

128128
ax.add_collection3d(patch)
129129
_autoscale_3d(ax, node)
130-
h.append(patch)
130+
h.append(ax)
131131

132132
np.random.set_state(rngstate)
133133
# plt.axis("equal")
@@ -226,7 +226,7 @@ def plottetra(node, elem, *args, **kwargs):
226226
ax.add_collection3d(patch)
227227

228228
_autoscale_3d(ax, node)
229-
h.append(patch)
229+
h.append(ax)
230230

231231
# Restore RNG state
232232
np.random.set_state(rngstate)
@@ -402,7 +402,7 @@ def plotmesh(node, *args, **kwargs):
402402
return None
403403
ax.plot(x[idx], y[idx], z[idx], **kwargs)
404404
_autoscale_3d(ax, node)
405-
if "hide" in extraarg and not extraarg["hide"]:
405+
if not "hold" in extraarg or not extraarg["hold"] or extraarg["hold"] == "off":
406406
plt.show(block=False)
407407
return ax
408408

@@ -440,7 +440,7 @@ def plotmesh(node, *args, **kwargs):
440440
ax = plottetra(node, elem[idx, :], opt, *args, **kwargs)
441441
handles.append(ax)
442442

443-
if "hide" in extraarg and not extraarg["hide"]:
443+
if not "hold" in extraarg or not extraarg["hold"] or extraarg["hold"] == "off":
444444
plt.show(block=False)
445445

446446
return handles if len(handles) > 1 else handles[0]

test/run_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,15 +1107,15 @@ def __init__(self, *args, **kwargs):
11071107
self.fc = volface(self.el)[0]
11081108

11091109
def test_plotmesh_face(self):
1110-
patch = plotmesh(self.no, self.fc, "hide", True)
1110+
patch = plotmesh(self.no, self.fc, "hold", True)
11111111
facecolors = np.array(patch[0].get_facecolors())
11121112
expected_fc = [9.0, 8.6803, 9.0, 20.0]
11131113

11141114
self.assertEqual(len(facecolors), 20)
11151115
self.assertEqual(np.round(np.sum(facecolors, axis=0), 4).tolist(), expected_fc)
11161116

11171117
def test_plotmesh_elem(self):
1118-
patch = plotmesh(self.no, self.el, "hide", True)
1118+
patch = plotmesh(self.no, self.el, "hold", True)
11191119
facecolors = np.array(patch[0].get_facecolors())
11201120
expected_fc = [9.0, 8.6803, 9.0, 20.0]
11211121

@@ -1126,7 +1126,7 @@ def test_plotmesh_elemlabel(self):
11261126
patch = plotmesh(
11271127
self.no,
11281128
np.hstack((self.el, np.ones(self.el.shape[0], dtype=int).reshape(-1, 1))),
1129-
"hide",
1129+
"hold",
11301130
True,
11311131
)
11321132
facecolors = np.array(patch[0].get_facecolors())
@@ -1140,7 +1140,7 @@ def test_plotmesh_facelabel(self):
11401140
self.no,
11411141
np.hstack((self.fc, np.array([1, 2] * 10).reshape(-1, 1))),
11421142
None,
1143-
"hide",
1143+
"hold",
11441144
True,
11451145
)
11461146
facecolors = np.array(patch[0].get_facecolors())
@@ -1150,15 +1150,15 @@ def test_plotmesh_facelabel(self):
11501150
self.assertEqual(np.unique(facecolors, axis=0).shape, expected_fc)
11511151

11521152
def test_plotmesh_elemnodeval(self):
1153-
patch = plotmesh(self.no[:, [0, 1, 2, 0]], self.el, "hide", True)
1153+
patch = plotmesh(self.no[:, [0, 1, 2, 0]], self.el, "hold", True)
11541154
facecolors = np.array(patch[0].get_facecolors())
11551155
expected_fc = [8.0, 10.4074, 8.0, 20.0]
11561156

11571157
self.assertEqual(len(facecolors), 20)
11581158
self.assertEqual(np.round(np.sum(facecolors, axis=0), 4).tolist(), expected_fc)
11591159

11601160
def test_plotmesh_facenodeval(self):
1161-
patch = plotmesh(self.no[:, [0, 1, 2, 0]], self.fc, "z < 3", "hide", True)
1161+
patch = plotmesh(self.no[:, [0, 1, 2, 0]], self.fc, "z < 3", "hold", True)
11621162
facecolors = np.array(patch[0].get_facecolors())
11631163
expected_fc = [7.0, 8.6728, 7.0, 18.0]
11641164

@@ -1167,7 +1167,7 @@ def test_plotmesh_facenodeval(self):
11671167

11681168
def test_plotmesh_selector(self):
11691169
patch = plotmesh(
1170-
self.no[:, [0, 1, 2, 0]], self.fc, "(z < 3) & (x < 2)", "hide", True
1170+
self.no[:, [0, 1, 2, 0]], self.fc, "(z < 3) & (x < 2)", "hold", True
11711171
)
11721172
facecolors = np.array(patch[0].get_facecolors())
11731173
expected_fc = [4.8877, 5.0, 4.451, 14.0]
@@ -1176,7 +1176,7 @@ def test_plotmesh_selector(self):
11761176
self.assertEqual(np.round(np.sum(facecolors, axis=0), 4).tolist(), expected_fc)
11771177

11781178
def test_plotmesh_elemselector(self):
1179-
patch = plotmesh(self.no, self.fc, "z < 2.5", "hide", True)
1179+
patch = plotmesh(self.no, self.fc, "z < 2.5", "hold", True)
11801180
facecolors = np.array(patch[0].get_facecolors())
11811181
expected_fc = [3.9102, 4.0, 2.9608, 10.0]
11821182

0 commit comments

Comments
 (0)