Skip to content

Commit 90be19d

Browse files
committed
introduce default block=None, plt.show() not called unless block is True or False. This is new standard for toolboxes
1 parent e60cf36 commit 90be19d

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

‎spatialmath/base/graphics.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ def _axes_dimensions(ax: plt.Axes) -> int:
14661466
ret = 3
14671467
elif classname == "Animate2":
14681468
ret = 2
1469-
print("_axes_dimensions ", ax, ret)
1469+
# print("_axes_dimensions ", ax, ret)
14701470
return ret
14711471

14721472
def axes_get_limits(ax: plt.Axes) -> NDArray:
@@ -1545,18 +1545,16 @@ def axes_logic(
15451545
if _axes_dimensions(ax) == dimensions and not new:
15461546
return ax
15471547
# otherwise it doesnt exist or dimension mismatch, create new axes
1548-
# print("create new axes")
15491548
else:
1550-
# print("no figs present, ax given")
1549+
# print("ax given", ax)
15511550
# axis was given
15521551

15531552
if _axes_dimensions(ax) == dimensions:
15541553
# print("use existing axes")
15551554
return ax
1556-
# mismatch in dimensions, create new axes
1557-
# print('create new axes')
1555+
# print("mismatch in dimensions, create new axes")
1556+
# print("create new axes")
15581557
plt.figure()
1559-
# no axis specified
15601558
if dimensions == 2:
15611559
ax = plt.axes()
15621560
if autoscale:

‎spatialmath/base/transforms2d.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ def _FindCorrespondences(
11211121

11221122
if _matplotlib_exists:
11231123
import matplotlib.pyplot as plt
1124+
11241125
# from mpl_toolkits.axisartist import Axes
11251126
from matplotlib.axes import Axes
11261127

@@ -1137,7 +1138,7 @@ def trplot2(
11371138
originsize: float = 20,
11381139
rviz: bool = False,
11391140
ax: Optional[Axes] = None,
1140-
block: bool = False,
1141+
block: Optional[bool] = None,
11411142
dims: Optional[ArrayLike] = None,
11421143
wtl: float = 0.2,
11431144
width: float = 1,
@@ -1168,7 +1169,7 @@ def trplot2(
11681169
:type arrow: bool
11691170
:param ax: the axes to plot into, defaults to current axes
11701171
:type ax: Axes3D reference
1171-
:param block: run the GUI main loop until all windows are closed, default True
1172+
:param block: run the GUI main loop until all windows are closed, default None
11721173
:type block: bool
11731174
:param dims: dimension of plot volume as [xmin, xmax, ymin, ymax]
11741175
:type dims: array_like(4)
@@ -1375,7 +1376,7 @@ def trplot2(
13751376
verticalalignment="center",
13761377
)
13771378

1378-
if block:
1379+
if block is not None:
13791380
# calling this at all, causes FuncAnimation to fail so when invoked from tranimate2 skip this bit
13801381
plt.show(block=block)
13811382
return ax

‎spatialmath/base/transforms3d.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ def trplot(
29162916
originsize: float = 20,
29172917
origincolor: str = "",
29182918
projection: str = "ortho",
2919-
block: bool = False,
2919+
block: Optional[bool] = None,
29202920
anaglyph: Optional[Union[bool, str, Tuple[str, float]]] = None,
29212921
wtl: float = 0.2,
29222922
width: Optional[float] = None,
@@ -3353,7 +3353,7 @@ def trplot(
33533353
if originsize > 0:
33543354
ax.scatter(xs=[o[0]], ys=[o[1]], zs=[o[2]], color=origincolor, s=originsize)
33553355

3356-
if block:
3356+
if block is not None:
33573357
# calling this at all, causes FuncAnimation to fail so when invoked from tranimate skip this bit
33583358
import matplotlib.pyplot as plt
33593359

@@ -3418,8 +3418,6 @@ def tranimate(T: Union[SO3Array, SE3Array], **kwargs) -> str:
34183418
anim.trplot(T, **kwargs)
34193419
return anim.run(**kwargs)
34203420

3421-
# plt.show(block=block)
3422-
34233421

34243422
if __name__ == "__main__": # pragma: no cover
34253423
# import sympy

0 commit comments

Comments
 (0)