Skip to content

Commit 02f2724

Browse files
committed
update rcParams processing
1 parent 2e4961c commit 02f2724

8 files changed

Lines changed: 163 additions & 56 deletions

File tree

control/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import collections
1212
import warnings
13+
1314
from .exception import ControlArgument
1415

1516
__all__ = ['defaults', 'set_defaults', 'reset_defaults',
@@ -121,6 +122,10 @@ def reset_defaults():
121122
# System level defaults
122123
defaults.update(_control_defaults)
123124

125+
from .ctrlplot import _ctrlplot_defaults, reset_rcParams
126+
reset_rcParams()
127+
defaults.update(_ctrlplot_defaults)
128+
124129
from .freqplot import _freqplot_defaults, _nyquist_defaults
125130
defaults.update(_freqplot_defaults)
126131
defaults.update(_nyquist_defaults)

control/ctrlplot.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
# ax = kwargs.pop('ax', None)
1111
# color = kwargs.pop('color', None)
1212
# label = kwargs.pop('label', None)
13-
# rcParams = config._get_param(
14-
# 'nameplot', 'rcParams', kwargs, _nameplot_defaults, pop=True)
13+
# rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
1514
#
1615
# # Make sure all keyword arguments were processed (if not checked later)
1716
# if kwargs:
@@ -89,21 +88,26 @@
8988

9089
from . import config
9190

92-
__all__ = ['ControlPlot', 'suptitle', 'get_plot_axes', 'pole_zero_subplots']
91+
__all__ = [
92+
'ControlPlot', 'suptitle', 'get_plot_axes', 'pole_zero_subplots',
93+
'rcParams', 'reset_rcParams']
9394

9495
#
9596
# Style parameters
9697
#
9798

98-
_ctrlplot_rcParams = mpl.rcParams.copy()
99-
_ctrlplot_rcParams.update({
99+
rcParams_default = {
100100
'axes.labelsize': 'small',
101101
'axes.titlesize': 'small',
102102
'figure.titlesize': 'medium',
103103
'legend.fontsize': 'x-small',
104104
'xtick.labelsize': 'small',
105105
'ytick.labelsize': 'small',
106-
})
106+
}
107+
_ctrlplot_rcParams = rcParams_default.copy() # provide access inside module
108+
rcParams = _ctrlplot_rcParams # provide access outside module
109+
110+
_ctrlplot_defaults = {'ctrlplot.rcParams': _ctrlplot_rcParams}
107111

108112

109113
#
@@ -190,15 +194,13 @@ def set_plot_title(self, title, frame='axes'):
190194
_update_plot_title(
191195
title, fig=self.figure, frame=frame, use_existing=False)
192196

193-
194197
#
195198
# User functions
196199
#
197200
# The functions below can be used by users to modify control plots or get
198201
# information about them.
199202
#
200203

201-
202204
def suptitle(
203205
title, fig=None, frame='axes', **kwargs):
204206
"""Add a centered title to a figure.
@@ -270,7 +272,7 @@ def pole_zero_subplots(
270272
2D array of axes
271273
272274
"""
273-
from .grid import sgrid, zgrid, nogrid
275+
from .grid import nogrid, sgrid, zgrid
274276
from .iosys import isctime
275277

276278
if rcParams is None:
@@ -307,6 +309,12 @@ def pole_zero_subplots(
307309
index += 1
308310
return ax_array
309311

312+
313+
def reset_rcParams():
314+
"""Reset rcParams to default values for control plots."""
315+
_ctrlplot_rcParams.update(rcParams_default)
316+
317+
310318
#
311319
# Utility functions
312320
#

control/freqplot.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
from . import config
2121
from .bdalg import feedback
22-
from .ctrlplot import ControlPlot, _add_arrows_to_line2D, _ctrlplot_rcParams, \
23-
_find_axes_center, _get_line_labels, _make_legend_labels, \
24-
_process_ax_keyword, _process_legend_keywords, _process_line_labels, \
25-
_update_plot_title
22+
from .ctrlplot import ControlPlot, _add_arrows_to_line2D, _find_axes_center, \
23+
_get_line_labels, _make_legend_labels, _process_ax_keyword, \
24+
_process_legend_keywords, _process_line_labels, _update_plot_title
2625
from .ctrlutil import unwrap
2726
from .exception import ControlMIMONotImplemented
2827
from .frdata import FrequencyResponseData
@@ -38,7 +37,6 @@
3837

3938
# Default values for module parameter variables
4039
_freqplot_defaults = {
41-
'freqplot.rcParams': _ctrlplot_rcParams,
4240
'freqplot.feature_periphery_decades': 1,
4341
'freqplot.number_of_samples': 1000,
4442
'freqplot.dB': False, # Plot gain in dB
@@ -186,7 +184,7 @@ def bode_plot(
186184
values with no plot.
187185
rcParams : dict
188186
Override the default parameters used for generating plots.
189-
Default is set by config.default['freqplot.rcParams'].
187+
Default is set by config.default['ctrlplot.rcParams'].
190188
show_legend : bool, optional
191189
Force legend to be shown if ``True`` or hidden if ``False``. If
192190
``None``, then show legend when there is more than one line on an
@@ -251,8 +249,7 @@ def bode_plot(
251249
'freqplot', 'wrap_phase', kwargs, _freqplot_defaults, pop=True)
252250
initial_phase = config._get_param(
253251
'freqplot', 'initial_phase', kwargs, None, pop=True)
254-
rcParams = config._get_param(
255-
'freqplot', 'rcParams', kwargs, _freqplot_defaults, pop=True)
252+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
256253
title_frame = config._get_param(
257254
'freqplot', 'title_frame', kwargs, _freqplot_defaults, pop=True)
258255

@@ -1026,7 +1023,6 @@ def gen_zero_centered_series(val_min, val_max, period):
10261023
# Generate the label, if needed
10271024
if show_legend == True or len(labels) > 1:
10281025
with plt.rc_context(rcParams):
1029-
print(f"{lines=}, {labels=}")
10301026
legend_array[i, j] = ax.legend(
10311027
lines, labels, loc=legend_map[i, j])
10321028
else:
@@ -1706,8 +1702,7 @@ def nyquist_plot(
17061702
'nyquist', 'max_curve_magnitude', kwargs, _nyquist_defaults, pop=True)
17071703
max_curve_offset = config._get_param(
17081704
'nyquist', 'max_curve_offset', kwargs, _nyquist_defaults, pop=True)
1709-
rcParams = config._get_param(
1710-
'freqplot', 'rcParams', kwargs, _freqplot_defaults, pop=True)
1705+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
17111706
start_marker = config._get_param(
17121707
'nyquist', 'start_marker', kwargs, _nyquist_defaults, pop=True)
17131708
start_marker_size = config._get_param(
@@ -2319,8 +2314,7 @@ def singular_values_plot(
23192314
'freqplot', 'Hz', kwargs, _freqplot_defaults, pop=True)
23202315
grid = config._get_param(
23212316
'freqplot', 'grid', kwargs, _freqplot_defaults, pop=True)
2322-
rcParams = config._get_param(
2323-
'freqplot', 'rcParams', kwargs, _freqplot_defaults, pop=True)
2317+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
23242318
title_frame = config._get_param(
23252319
'freqplot', 'title_frame', kwargs, _freqplot_defaults, pop=True)
23262320

control/nichols.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def nichols_plot(
9999
# Get parameter values
100100
grid = config._get_param('nichols', 'grid', grid, True)
101101
label = _process_line_labels(label)
102-
rcParams = config._get_param(
103-
'freqplot', 'rcParams', kwargs, _freqplot_defaults, pop=True)
102+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
104103

105104
# If argument was a singleton, turn it into a list
106105
if not isinstance(data, (tuple, list)):

control/phaseplot.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@
3737

3838
from . import config
3939
from .ctrlplot import ControlPlot, _add_arrows_to_line2D, \
40-
_ctrlplot_rcParams, _process_ax_keyword, _update_plot_title
40+
_process_ax_keyword, _update_plot_title
4141
from .exception import ControlNotImplemented
4242
from .nlsys import NonlinearIOSystem, find_eqpt, input_output_response
4343

4444
__all__ = ['phase_plane_plot', 'phase_plot', 'box_grid']
4545

4646
# Default values for module parameter variables
4747
_phaseplot_defaults = {
48-
'phaseplot.rcParams': _ctrlplot_rcParams,
4948
'phaseplot.arrows': 2, # number of arrows around curve
5049
'phaseplot.arrow_size': 8, # pixel size for arrows
5150
'phaseplot.separatrices_radius': 0.1 # initial radius for separatrices
@@ -146,8 +145,7 @@ def phase_plane_plot(
146145
params = kwargs.get('params', None)
147146
sys = _create_system(sys, params)
148147
pointdata = [-1, 1, -1, 1] if pointdata is None else pointdata
149-
rcParams = config._get_param(
150-
'timeplot', 'rcParams', kwargs, _phaseplot_defaults, pop=True)
148+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
151149

152150
# Create axis if needed
153151
user_ax = ax
@@ -223,7 +221,7 @@ def _create_kwargs(global_kwargs, local_kwargs, **other_kwargs):
223221
if user_ax is None:
224222
if title is None:
225223
title = f"Phase portrait for {sys.name}"
226-
_update_plot_title(title, use_existing=False)
224+
_update_plot_title(title, use_existing=False, rcParams=rcParams)
227225
ax.set_xlabel(sys.state_labels[0])
228226
ax.set_ylabel(sys.state_labels[1])
229227
plt.tight_layout()
@@ -281,8 +279,7 @@ def vectorfield(
281279
282280
"""
283281
# Process keywords
284-
rcParams = config._get_param(
285-
'timeplot', 'rcParams', kwargs, _phaseplot_defaults, pop=True)
282+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
286283

287284
# Get system parameters
288285
params = kwargs.pop('params', None)
@@ -375,8 +372,7 @@ def streamlines(
375372
376373
"""
377374
# Process keywords
378-
rcParams = config._get_param(
379-
'timeplot', 'rcParams', kwargs, _phaseplot_defaults, pop=True)
375+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
380376

381377
# Get system parameters
382378
params = kwargs.pop('params', None)
@@ -481,8 +477,7 @@ def equilpoints(
481477
482478
"""
483479
# Process keywords
484-
rcParams = config._get_param(
485-
'timeplot', 'rcParams', kwargs, _phaseplot_defaults, pop=True)
480+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
486481

487482
# Get system parameters
488483
params = kwargs.pop('params', None)
@@ -570,8 +565,7 @@ def separatrices(
570565
571566
"""
572567
# Process keywords
573-
rcParams = config._get_param(
574-
'timeplot', 'rcParams', kwargs, _phaseplot_defaults, pop=True)
568+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
575569

576570
# Get system parameters
577571
params = kwargs.pop('params', None)

control/pzmap.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ def pole_zero_plot(
276276
label = _process_line_labels(label)
277277
marker_size = config._get_param('pzmap', 'marker_size', marker_size, 6)
278278
marker_width = config._get_param('pzmap', 'marker_width', marker_width, 1.5)
279-
rcParams = config._get_param(
280-
'freqplot', 'rcParams', kwargs, _freqplot_defaults, pop=True)
279+
rcParams = config._get_param('ctrlplot', 'rcParams', kwargs, pop=True)
281280
user_ax = ax
282281
xlim_user, ylim_user = xlim, ylim
283282

0 commit comments

Comments
 (0)