8000 test for correct grid and no plot. fix pzmap config handling · basicmachines/python-control@5632796 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5632796

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

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

control/grid.py

Lines changed: 3 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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 8000 ://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

control/tests/pzmap_test.py

Lines changed: 20 additions & 2 deletions
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

@@ -54,10 +56,26 @@ def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup):
5456

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

6280

6381
def test_pzmap_warns():

0 commit comments

Comments
 (0)
0