Skip to content

Commit 07f2d1a

Browse files
committed
consistent changes to semantics of block. Can be None, False or True
1 parent e660b7f commit 07f2d1a

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

roboticstoolbox/mobile/EKF.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -1000,13 +1000,13 @@ def get_xyt(self):
10001000
xyt = None
10011001
return xyt
10021002

1003-
def plot_xy(self, *args, block=False, **kwargs):
1003+
def plot_xy(self, *args, block=None, **kwargs):
10041004
"""
10051005
Plot estimated vehicle position
10061006
10071007
:param args: position arguments passed to :meth:`~matplotlib.axes.Axes.plot`
10081008
:param kwargs: keywords arguments passed to :meth:`~matplotlib.axes.Axes.plot`
1009-
:param block: hold plot until figure is closed, defaults to False
1009+
:param block: hold plot until figure is closed, defaults to None
10101010
:type block: bool, optional
10111011
10121012
Plot the estimated vehicle path in the xy-plane.
@@ -1018,16 +1018,19 @@ def plot_xy(self, *args, block=False, **kwargs):
10181018
kwargs["color"] = "r"
10191019
xyt = self.get_xyt()
10201020
plt.plot(xyt[:, 0], xyt[:, 1], *args, **kwargs)
1021-
# plt.show(block=block)
1021+
if block is not None:
1022+
plt.show(block=block)
10221023

1023-
def plot_ellipse(self, confidence=0.95, N=10, **kwargs):
1024+
def plot_ellipse(self, confidence=0.95, N=10, block=None, **kwargs):
10241025
"""
10251026
Plot uncertainty ellipses
10261027
10271028
:param confidence: ellipse confidence interval, defaults to 0.95
10281029
:type confidence: float, optional
10291030
:param N: number of ellipses to plot, defaults to 10
10301031
:type N: int, optional
1032+
:param block: hold plot until figure is closed, defaults to None
1033+
:type block: bool, optional
10311034
:param kwargs: arguments passed to :meth:`spatialmath.base.graphics.plot_ellipse`
10321035
10331036
Plot ``N`` uncertainty ellipses spaced evenly along the trajectory.
@@ -1062,15 +1065,19 @@ def plot_ellipse(self, confidence=0.95, N=10, **kwargs):
10621065
inverted=True,
10631066
**kwargs,
10641067
)
1068+
if block is not None:
1069+
plt.show(block=block)
10651070

1066-
def plot_error(self, bgcolor="r", confidence=0.95, ax=None, **kwargs):
1071+
def plot_error(self, bgcolor="r", confidence=0.95, ax=None, block=None, **kwargs):
10671072
r"""
10681073
Plot error with uncertainty bounds
10691074
10701075
:param bgcolor: background color, defaults to 'r'
10711076
:type bgcolor: str, optional
10721077
:param confidence: confidence interval, defaults to 0.95
10731078
:type confidence: float, optional
1079+
:param block: hold plot until figure is closed, defaults to None
1080+
:type block: bool, optional
10741081
10751082
Plot the error between actual and estimated vehicle
10761083
path :math:`(x, y, \theta)`` versus time as three stacked plots.
@@ -1128,6 +1135,9 @@ def plot_error(self, bgcolor="r", confidence=0.95, ax=None, **kwargs):
11281135
ax.set_ylabel(labels[k] + " error")
11291136
ax.set_xlim(0, t[-1])
11301137

1138+
if block is not None:
1139+
plt.show(block=block)
1140+
11311141
# subplot(opt.nplots*100+12)
11321142
# if opt.confidence
11331143
# edge = [pxy(:,2); -pxy(end:-1:1,2)];
@@ -1176,7 +1186,7 @@ def get_map(self):
11761186
xy.append(xf)
11771187
return np.array(xy)
11781188

1179-
def plot_map(self, marker=None, ellipse=None, confidence=0.95):
1189+
def plot_map(self, marker=None, ellipse=None, confidence=0.95, block=None):
11801190
"""
11811191
Plot estimated landmarks
11821192
@@ -1186,6 +1196,8 @@ def plot_map(self, marker=None, ellipse=None, confidence=0.95):
11861196
:type ellipse: dict, optional
11871197
:param confidence: ellipse confidence interval, defaults to 0.95
11881198
:type confidence: float, optional
1199+
:param block: hold plot until figure is closed, defaults to None
1200+
:type block: bool, optional
11891201
11901202
Plot a marker and covariance ellipses for each estimated landmark.
11911203
@@ -1232,6 +1244,8 @@ def plot_map(self, marker=None, ellipse=None, confidence=0.95):
12321244
**ellipse,
12331245
)
12341246
# plot_ellipse( P * chi2inv_rtb(opt.confidence, 2), xf, args{:});
1247+
if block is not None:
1248+
plt.show(block=block)
12351249

12361250
def get_P(self, k=None):
12371251
"""

roboticstoolbox/mobile/OccGrid.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def w2g(self, p):
258258
"""
259259
return (np.round((p - self._origin) / self._cellsize)).astype(int)
260260

261-
def plot(self, map=None, ax=None, block=False, **kwargs):
261+
def plot(self, map=None, ax=None, block=None, **kwargs):
262262
"""
263263
Plot the occupancy grid (superclass)
264264
@@ -267,7 +267,7 @@ def plot(self, map=None, ax=None, block=False, **kwargs):
267267
:type map: ndarray(N,M), optional
268268
:param ax: matplotlib axes to plot into, defaults to None
269269
:type ax: Axes2D, optional
270-
:param block: block until plot is dismissed, defaults to False
270+
:param block: block until plot is dismissed, defaults to None
271271
:type block: bool, optional
272272
:param kwargs: arguments passed to ``imshow``
273273
@@ -288,7 +288,8 @@ def plot(self, map=None, ax=None, block=False, **kwargs):
288288
ax.imshow(map, origin="lower", interpolation=None, **kwargs)
289289
ax.set_xlabel("x")
290290
ax.set_ylabel("y")
291-
plt.show(block=block)
291+
if block is not None:
292+
plt.show(block=block)
292293

293294
def line_w(self, p1, p2):
294295
"""
@@ -518,13 +519,14 @@ def iscollision(self, polygon):
518519
"""
519520
return polygon.intersects(self.polygons)
520521

521-
def plot(self, block=False):
522+
def plot(self, block=None):
522523
base.plotvol2(self.workspace)
523524

524525
for polygon in self.polygons:
525526
polygon.plot(color="r")
526527

527-
plt.show(block=block)
528+
if block is not None:
529+
plt.show(block=block)
528530

529531
def isoccupied(self, p):
530532
"""

roboticstoolbox/mobile/ParticleFilter.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,13 @@ def get_std(self):
501501
"""
502502
return np.array([h.std for h in self._history])
503503

504-
def plot_xy(self, block=False, **kwargs):
504+
def plot_xy(self, block=None, **kwargs):
505505
r"""
506506
Plot estimated vehicle position
507507
508508
:param args: position arguments passed to :meth:`~matplotlib.axes.Axes.plot`
509509
:param kwargs: keywords arguments passed to :meth:`~matplotlib.axes.Axes.plot`
510-
:param block: hold plot until figure is closed, defaults to False
510+
:param block: hold plot until figure is closed, defaults to None
511511
:type block: bool, optional
512512
513513
Plot the estimated vehicle path in the xy-plane.
@@ -516,4 +516,5 @@ def plot_xy(self, block=False, **kwargs):
516516
"""
517517
xyt = self.get_xyt()
518518
plt.plot(xyt[:, 0], xyt[:, 1], **kwargs)
519-
# plt.show(block=block)
519+
if block is not None:
520+
plt.show(block=block)

roboticstoolbox/mobile/PoseGraph.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def w2g(self, w):
386386
def g2w(self, g):
387387
return (np.r_[g] - self._ngrid / 2) * self._cellsize + self._centre
388388

389-
def plot_occgrid(self, w, block=True):
389+
def plot_occgrid(self, w, block=None):
390390

391391
bl = self.g2w([0, 0])
392392
tr = self.g2w([w.shape[1], w.shape[0]])
@@ -399,7 +399,9 @@ def plot_occgrid(self, w, block=True):
399399
plt.imshow(w, cmap="gray", extent=[bl[0], tr[0], bl[1], tr[1]])
400400
plt.xlabel("x")
401401
plt.ylabel("y")
402-
plt.show(block=block)
402+
403+
if block is not None:
404+
plt.show(block=block)
403405

404406
# The following methods were inspired by, and modeled on, the MATLAB/Octave file
405407
# ls-slam.m by Giorgio Grisetti and Gian Diego Tipaldi.

roboticstoolbox/mobile/Vehicle.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,11 @@ def stopsim(self):
792792
# vertices = np.array(vertices).T
793793
# base.plot_poly(SE2(x) * vertices, close=True, **kwargs)
794794

795-
def plot_xy(self, *args, block=False, **kwargs):
795+
def plot_xy(self, *args, block=None, **kwargs):
796796
"""
797797
Plot xy-path from history
798798
799-
:param block: block until plot dismissed, defaults to False
799+
:param block: block until plot dismissed, defaults to None
800800
:type block: bool, optional
801801
:param args: positional arguments passed to :meth:`~matplotlib.axes.Axes.plot`
802802
:param kwargs: keyword arguments passed to :meth:`~matplotlib.axes.Axes.plot`
@@ -811,9 +811,10 @@ def plot_xy(self, *args, block=False, **kwargs):
811811
kwargs['color'] = 'b'
812812
xyt = self.x_hist
813813
plt.plot(xyt[:, 0], xyt[:, 1], *args, **kwargs)
814-
plt.show(block=block)
814+
if block is not None:
815+
plt.show(block=block)
815816

816-
def plot_xyt(self, block=False, **kwargs):
817+
def plot_xyt(self, block=None, **kwargs):
817818
"""
818819
Plot configuration vs time from history
819820
@@ -829,10 +830,10 @@ def plot_xyt(self, block=False, **kwargs):
829830
"""
830831
xyt = self.x_hist
831832
t = np.arange(0, xyt.shape[0] * self._dt, self._dt)
832-
plt.plot(xyt[:,0], xyt[:, :], **kwargs)
833-
plt.legend(['x', 'y', '$\\theta$'])
834-
plt.show(block=block)
835-
833+
plt.plot(xyt[:, 0], xyt[:, :], **kwargs)
834+
plt.legend(["x", "y", "$\\theta$"])
835+
if block is not None:
836+
plt.show(block=block)
836837

837838
# def path(self, t=10, u=None, x0=None):
838839
# """

0 commit comments

Comments
 (0)