Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix processing of custom font sizes (w/ unit test)
  • Loading branch information
murrayrm committed Jul 10, 2023
commit 1a9e64fc4ea3ace4b20f7121fd95e449ab197c34
27 changes: 27 additions & 0 deletions control/tests/timeplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,33 @@ def test_linestyles():
assert lines[6].get_color() == 'red' and lines[6].get_linestyle() == '--'
assert lines[7].get_color() == 'green' and lines[7].get_linestyle() == '--'


def test_rcParams():
sys = ct.rss(2, 2, 2)

# Create new set of rcParams
my_rcParams = {
'axes.labelsize': 10,
'axes.titlesize': 10,
'figure.titlesize': 12,
'legend.fontsize': 10,
'xtick.labelsize': 10,
'ytick.labelsize': 10,
}

# Generate a figure with the new rcParams
out = ct.step_response(sys).plot(rcParams=my_rcParams)
ax = out[0, 0][0].axes
fig = ax.figure

# Check to make sure new settings were used
assert ax.xaxis.get_label().get_fontsize() == 10
assert ax.yaxis.get_label().get_fontsize() == 10
assert ax.title.get_fontsize() == 10
assert ax.xaxis._get_tick_label_size('x') == 10
assert ax.yaxis._get_tick_label_size('y') == 10
assert fig._suptitle.get_fontsize() == 12

def test_relabel():
sys1 = ct.rss(2, inputs='u', outputs='y')
sys2 = ct.rss(1, 1, 1) # uses default i/o labels
Expand Down
10 changes: 6 additions & 4 deletions control/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def time_response_plot(
# Set up defaults
time_label = config._get_param(
'timeplot', 'time_label', kwargs, _timeplot_defaults, pop=True)
timeplot_rcParams = config._get_param(
'timeplot', 'rcParams', kwargs, _timeplot_defaults, pop=True)

if kwargs.get('input_props', None) and len(fmt) > 0:
warn("input_props ignored since fmt string was present")
Expand Down Expand Up @@ -288,7 +290,7 @@ def time_response_plot(

# Create new axes, if needed, and customize them
if ax is None:
with plt.rc_context(_timeplot_rcParams):
with plt.rc_context(timeplot_rcParams):
ax_array = fig.subplots(nrows, ncols, sharex=True, squeeze=False)
fig.set_tight_layout(True)
fig.align_labels()
Expand Down Expand Up @@ -504,7 +506,7 @@ def _make_line_label(signal_index, signal_labels, trace_index):
else:
label = f"Trace {trace}"

with plt.rc_context(_timeplot_rcParams):
with plt.rc_context(timeplot_rcParams):
ax_array[0, trace].set_title(label)

# Label the outputs
Expand Down Expand Up @@ -629,7 +631,7 @@ def _make_line_label(signal_index, signal_labels, trace_index):

# Update the labels to remove common strings
if len(labels) > 1 and legend_map[i, j] != None:
with plt.rc_context(_timeplot_rcParams):
with plt.rc_context(timeplot_rcParams):
ax.legend(labels, loc=legend_map[i, j])

#
Expand Down Expand Up @@ -663,7 +665,7 @@ def _make_line_label(signal_index, signal_labels, trace_index):
new_title = old_title + separator + new_title[common_len:]

# Add the title
with plt.rc_context(_timeplot_rcParams):
with plt.rc_context(timeplot_rcParams):
fig.suptitle(new_title)

return out
Expand Down