|
72 | 72 | # |
73 | 73 | # return ControlPlot(lines, ax_array, fig, legend=legend_map) |
74 | 74 |
|
| 75 | +import itertools |
75 | 76 | import warnings |
76 | 77 | from os.path import commonprefix |
77 | 78 |
|
|
81 | 82 |
|
82 | 83 | from . import config |
83 | 84 |
|
84 | | -__all__ = ['ControlPlot', 'suptitle', 'get_plot_axes'] |
| 85 | +__all__ = ['ControlPlot', 'suptitle', 'get_plot_axes', 'pole_zero_subplots'] |
85 | 86 |
|
86 | 87 | # |
87 | 88 | # Style parameters |
@@ -241,14 +242,76 @@ def get_plot_axes(line_array): |
241 | 242 | else: |
242 | 243 | return _get_axes(line_array) |
243 | 244 |
|
| 245 | + |
| 246 | +def pole_zero_subplots( |
| 247 | + nrows, ncols, grid=None, dt=None, fig=None, scaling=None, |
| 248 | + rcParams=None): |
| 249 | + """Create axes for pole/zero plot. |
| 250 | +
|
| 251 | + Parameters |
| 252 | + ---------- |
| 253 | + nrows, ncols : int |
| 254 | + Number of rows and columns |
| 255 | + grid : True, False, or 'empty', optional |
| 256 | + Grid style to use. Can also be a list, in which case each subplot |
| 257 | + will have a different style (columns then rows). |
| 258 | + dt : timebase, option |
| 259 | + Timebase for each subplot (or a list of timebases). |
| 260 | + scaling : 'auto', 'equal', or None |
| 261 | + Scaling to apply to the subplots. |
| 262 | + fig : :class:`matplotlib.figure.Figure` |
| 263 | + Figure to use for creating subplots. |
| 264 | +
|
| 265 | + Returns |
| 266 | + ------- |
| 267 | + ax_array : array |
| 268 | + 2D array of axes |
| 269 | +
|
| 270 | + """ |
| 271 | + from .grid import sgrid, zgrid, nogrid |
| 272 | + from .iosys import isctime |
| 273 | + |
| 274 | + if rcParams is None: |
| 275 | + rcParams = _ctrlplot_rcParams |
| 276 | + |
| 277 | + if fig is None: |
| 278 | + fig = plt.gcf() |
| 279 | + |
| 280 | + if not isinstance(grid, list): |
| 281 | + grid = [grid] * nrows * ncols |
| 282 | + if not isinstance(dt, list): |
| 283 | + dt = [dt] * nrows * ncols |
| 284 | + |
| 285 | + ax_array = np.full((nrows, ncols), None) |
| 286 | + index = 0 |
| 287 | + with plt.rc_context(rcParams): |
| 288 | + for row, col in itertools.product(range(nrows), range(ncols)): |
| 289 | + match grid[index], isctime(dt=dt[index]): |
| 290 | + case 'empty', _: # empty grid |
| 291 | + ax_array[row, col] = fig.add_subplot(nrows, ncols, index+1) |
| 292 | + |
| 293 | + case True, True: # continuous time grid |
| 294 | + ax_array[row, col], _ = sgrid( |
| 295 | + (nrows, ncols, index+1), scaling=scaling) |
| 296 | + |
| 297 | + case True, False: # discrete time grid |
| 298 | + ax_array[row, col] = fig.add_subplot(nrows, ncols, index+1) |
| 299 | + zgrid(ax=ax_array[row, col], scaling=scaling) |
| 300 | + |
| 301 | + case False | None, _: # no grid (just stability boundaries) |
| 302 | + ax_array[row, col] = fig.add_subplot(nrows, ncols, index+1) |
| 303 | + nogrid( |
| 304 | + ax=ax_array[row, col], dt=dt[index], scaling=scaling) |
| 305 | + index += 1 |
| 306 | + return ax_array |
| 307 | + |
244 | 308 | # |
245 | 309 | # Utility functions |
246 | 310 | # |
247 | 311 | # These functions are used by plotting routines to provide a consistent way |
248 | 312 | # of processing and displaying information. |
249 | 313 | # |
250 | 314 |
|
251 | | - |
252 | 315 | def _process_ax_keyword( |
253 | 316 | axs, shape=(1, 1), rcParams=None, squeeze=False, clear_text=False, |
254 | 317 | create_axes=True): |
|
0 commit comments