8000 plotvol2/3 now take a new option, guaranteed to create a new figure · rocsys/spatialmath-python@0ce4994 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ce4994

Browse files
committed
plotvol2/3 now take a new option, guaranteed to create a new figure
1 parent c8141fb commit 0ce4994

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

spatialmath/base/graphics.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,7 @@ def axes_logic(
14951495
dimensions: int,
14961496
projection: Optional[str] = "ortho",
14971497
autoscale: Optional[bool] = True,
1498+
new: Optional[bool] = False,
14981499
) -> Union[plt.Axes, Axes3D]:
14991500
"""
15001501
Axis creation logic
@@ -1505,6 +1506,8 @@ def axes_logic(
15051506
:type dimensions: int
15061507
:param projection: 3D projection type, defaults to 'ortho'
15071508
:type projection: str, optional
1509+
:param new: create a new figure, defaults to False
1510+
:type new: bool
15081511
:return: axes to draw in
15091512
:rtype: Axes3DSubplot or AxesSubplot
15101513
@@ -1514,6 +1517,9 @@ def axes_logic(
15141517
If the dimensions do not match, or no figure/axes currently exist,
15151518
then ``plt.axes()`` is called to create one.
15161519
1520+
If ``new`` is True then a new 3D axes is created regardless of whether the
1521+
current axis is 3D.
1522+
15171523
Used by all plot_xxx() functions in this module.
15181524
"""
15191525

@@ -1533,7 +1539,7 @@ def axes_logic(
15331539
if naxes > 0:
15341540
ax = plt.gca() # get current axes
15351541
# print(f"ax has {_axes_dimensions(ax)} dimensions")
1536-
if _axes_dimensions(ax) == dimensions:
1542+
if _axes_dimensions(ax) == dimensions and not new:
15371543
return ax
15381544
# otherwise it doesnt exist or dimension mismatch, create new axes
15391545
# print("create new axes")
@@ -1566,6 +1572,7 @@ def plotvol2(
15661572
equal: Optional[bool] = True,
15671573
grid: Optional[bool] = False,
15681574
labels: Optional[bool] = True,
1575+
new: Optional[bool] = False,
15691576
) -> plt.Axes:
15701577
"""
15711578
Create 2D plot area
@@ -1589,9 +1596,11 @@ def plotvol2(
15891596
15901597
:seealso: :func:`plotvol3`, :func:`expand_dims`
15911598
"""
1599+
ax = axes_logic(ax, 2, new=new)
1600+
15921601
dims = expand_dims(dim, 2)
1593-
if ax is None:
1594-
ax = plt.subplot()
1602+
# if ax is None:
1603+
# ax = plt.subplot()
15951604
ax.axis(dims)
15961605
if labels:
15971606
ax.set_xlabel("X")
@@ -1614,6 +1623,7 @@ def plotvol3(
16141623
grid: Optional[bool] = False,
16151624
labels: Optional[bool] = True,
16161625
projection: Optional[str] = "ortho",
1626+
new: Optional[bool] = False,
16171627
) -> Axes3D:
16181628
"""
16191629
Create 3D plot volume
@@ -1638,7 +1648,7 @@ def plotvol3(
16381648
:seealso: :func:`plotvol2`, :func:`expand_dims`
16391649
"""
16401650
# create an axis if none existing
1641-
ax = axes_logic(ax, 3, projection=projection)
1651+
ax = axes_logic(ax, 3, projection=projection, new=new)
16421652

16431653
if dim is None:
16441654
ax.autoscale(True)

0 commit comments

Comments
 (0)
0