@@ -1495,6 +1495,7 @@ def axes_logic(
1495
1495
dimensions : int ,
1496
1496
projection : Optional [str ] = "ortho" ,
1497
1497
autoscale : Optional [bool ] = True ,
1498
+ new : Optional [bool ] = False ,
1498
1499
) -> Union [plt .Axes , Axes3D ]:
1499
1500
"""
1500
1501
Axis creation logic
@@ -1505,6 +1506,8 @@ def axes_logic(
1505
1506
:type dimensions: int
1506
1507
:param projection: 3D projection type, defaults to 'ortho'
1507
1508
:type projection: str, optional
1509
+ :param new: create a new figure, defaults to False
1510
+ :type new: bool
1508
1511
:return: axes to draw in
1509
1512
:rtype: Axes3DSubplot or AxesSubplot
1510
1513
@@ -1514,6 +1517,9 @@ def axes_logic(
1514
1517
If the dimensions do not match, or no figure/axes currently exist,
1515
1518
then ``plt.axes()`` is called to create one.
1516
1519
1520
+ If ``new`` is True then a new 3D axes is created regardless of whether the
1521
+ current axis is 3D.
1522
+
1517
1523
Used by all plot_xxx() functions in this module.
1518
1524
"""
1519
1525
@@ -1533,7 +1539,7 @@ def axes_logic(
1533
1539
if naxes > 0 :
1534
1540
ax = plt .gca () # get current axes
1535
1541
# print(f"ax has {_axes_dimensions(ax)} dimensions")
1536
- if _axes_dimensions (ax ) == dimensions :
1542
+ if _axes_dimensions (ax ) == dimensions and not new :
1537
1543
return ax
1538
1544
# otherwise it doesnt exist or dimension mismatch, create new axes
1539
1545
# print("create new axes")
@@ -1566,6 +1572,7 @@ def plotvol2(
1566
1572
equal : Optional [bool ] = True ,
1567
1573
grid : Optional [bool ] = False ,
1568
1574
labels : Optional [bool ] = True ,
1575
+ new : Optional [bool ] = False ,
1569
1576
) -> plt .Axes :
1570
1577
"""
1571
1578
Create 2D plot area
@@ -1589,9 +1596,11 @@ def plotvol2(
1589
1596
1590
1597
:seealso: :func:`plotvol3`, :func:`expand_dims`
1591
1598
"""
1599
+ ax = axes_logic (ax , 2 , new = new )
1600
+
1592
1601
dims = expand_dims (dim , 2 )
1593
- if ax is None :
1594
- ax = plt .subplot ()
1602
+ # if ax is None:
1603
+ # ax = plt.subplot()
1595
1604
ax .axis (dims )
1596
1605
if labels :
1597
1606
ax .set_xlabel ("X" )
@@ -1614,6 +1623,7 @@ def plotvol3(
1614
1623
grid : Optional [bool ] = False ,
1615
1624
labels : Optional [bool ] = True ,
1616
1625
projection : Optional [str ] = "ortho" ,
1626
+ new : Optional [bool ] = False ,
1617
1627
) -> Axes3D :
1618
1628
"""
1619
1629
Create 3D plot volume
@@ -1638,7 +1648,7 @@ def plotvol3(
1638
1648
:seealso: :func:`plotvol2`, :func:`expand_dims`
1639
1649
"""
1640
1650
# create an axis if none existing
1641
- ax = axes_logic (ax , 3 , projection = projection )
1651
+ ax = axes_logic (ax , 3 , projection = projection , new = new )
1642
1652
1643
1653
if dim is None :
1644
1654
ax .autoscale (True )
0 commit comments