Skip to content

Commit b292feb

Browse files
committed
test for correct grid and no plot. fix pzmap config handling
1 parent 2ca5220 commit b292feb

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

control/grid.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
3434
# Changed from 180 to 360 to be able to span only
3535
# 90-270 (left hand side)
3636
lon -= 360. * ((lon - lon0) > 360.)
37-
if self.lat_cycle is not None:
37+
if self.lat_cycle is not None: # pragma: no cover
3838
lat0 = np.nanmin(lat)
39-
# Changed from 180 to 360 to be able to span only
40-
# 90-270 (left hand side)
41-
lat -= 360. * ((lat - lat0) > 360.)
39+
lat -= 360. * ((lat - lat0) > 180.)
4240

4341
lon_min, lon_max = np.nanmin(lon), np.nanmax(lon)
4442
lat_min, lat_max = np.nanmin(lat), np.nanmax(lat)
@@ -49,7 +47,7 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
4947
# check cycle
5048
if self.lon_cycle:
5149
lon_max = min(lon_max, lon_min + self.lon_cycle)
52-
if self.lat_cycle:
50+
if self.lat_cycle: # pragma: no cover
5351
lat_max = min(lat_max, lat_min + self.lat_cycle)
5452

5553
if self.lon_minmax is not None:

control/pzmap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# TODO: Implement more elegant cross-style axes. See:
5959
# http://matplotlib.sourceforge.net/examples/axes_grid/demo_axisline_style.html
6060
# http://matplotlib.sourceforge.net/examples/axes_grid/demo_curvelinear_grid.html
61-
def pzmap(sys, plot=True, grid=False, title='Pole Zero Map', **kwargs):
61+
def pzmap(sys, plot=None, grid=None, title='Pole Zero Map', **kwargs):
6262
"""
6363
Plot a pole/zero map for a linear system.
6464
@@ -90,6 +90,7 @@ def pzmap(sys, plot=True, grid=False, title='Pole Zero Map', **kwargs):
9090
plot = config._get_param('pzmap', 'plot', plot, True)
9191
grid = config._get_param('pzmap', 'grid', grid, False)
9292

93+
9394
if not isinstance(sys, LTI):
9495
raise TypeError('Argument ``sys``: must be a linear system.')
9596

control/tests/pzmap_test.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
@author: bnavigator
77
"""
88

9+
import matplotlib
910
import numpy as np
1011
import pytest
1112
from matplotlib import pyplot as plt
13+
from mpl_toolkits.axisartist import Axes as mpltAxes
1214

1315
from control import TransferFunction, config, pzmap
1416

@@ -45,6 +47,7 @@ def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup):
4547
for k in ['plot', 'grid']:
4648
if k in pzkwargs:
4749
v = pzkwargs.pop(k)
50+
print("setting {} to {}".format(k,v))
4851
config.set_defaults('pzmap', **{k: v})
4952

5053
P, Z = pzmap(T, **pzkwargs)
@@ -54,10 +57,26 @@ def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup):
5457

5558
if kwargs.get('plot', True):
5659
ax = plt.gca()
60+
5761
assert ax.get_title() == kwargs.get('title', 'Pole Zero Map')
62+
63+
# FIXME: This won't work when zgrid and sgrid are unified
64+
children = ax.get_children()
65+
has_zgrid = False
66+
for c in children:
67+
if isinstance(c, matplotlib.text.Annotation):
68+
if r'\pi' in c.get_text():
69+
has_zgrid = True
70+
has_sgrid = isinstance(ax, mpltAxes)
71+
5872
if kwargs.get('grid', False):
59-
# TODO: check for correct grid
60-
pass
73+
assert dt == has_zgrid
74+
assert dt != has_sgrid
75+
else:
76+
assert not has_zgrid
77+
assert not has_sgrid
78+
else:
79+
assert not plt.get_fignums()
6180

6281

6382
def test_pzmap_warns():

0 commit comments

Comments
 (0)