Skip to content

Commit b1661a3

Browse files
committed
fix processing of custom font sizes (w/ unit test)
1 parent dd6983e commit b1661a3

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

control/tests/timeplot_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,33 @@ def test_linestyles():
341341
assert lines[6].get_color() == 'red' and lines[6].get_linestyle() == '--'
342342
assert lines[7].get_color() == 'green' and lines[7].get_linestyle() == '--'
343343

344+
345+
def test_rcParams():
346+
sys = ct.rss(2, 2, 2)
347+
348+
# Create new set of rcParams
349+
my_rcParams = {
350+
'axes.labelsize': 10,
351+
'axes.titlesize': 10,
352+
'figure.titlesize': 12,
353+
'legend.fontsize': 10,
354+
'xtick.labelsize': 10,
355+
'ytick.labelsize': 10,
356+
}
357+
358+
# Generate a figure with the new rcParams
359+
out = ct.step_response(sys).plot(rcParams=my_rcParams)
360+
ax = out[0, 0][0].axes
361+
fig = ax.figure
362+
363+
# Check to make sure new settings were used
364+
assert ax.xaxis.get_label().get_fontsize() == 10
365+
assert ax.yaxis.get_label().get_fontsize() == 10
366+
assert ax.title.get_fontsize() == 10
367+
assert ax.xaxis._get_tick_label_size('x') == 10
368+
assert ax.yaxis._get_tick_label_size('y') == 10
369+
assert fig._suptitle.get_fontsize() == 12
370+
344371
def test_relabel():
345372
sys1 = ct.rss(2, inputs='u', outputs='y')
346373
sys2 = ct.rss(1, 1, 1) # uses default i/o labels

control/timeplot.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def time_response_plot(
160160
# Set up defaults
161161
time_label = config._get_param(
162162
'timeplot', 'time_label', kwargs, _timeplot_defaults, pop=True)
163+
timeplot_rcParams = config._get_param(
164+
'timeplot', 'rcParams', kwargs, _timeplot_defaults, pop=True)
163165

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

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

507-
with plt.rc_context(_timeplot_rcParams):
509+
with plt.rc_context(timeplot_rcParams):
508510
ax_array[0, trace].set_title(label)
509511

510512
# Label the outputs
@@ -629,7 +631,7 @@ def _make_line_label(signal_index, signal_labels, trace_index):
629631

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

635637
#
@@ -663,7 +665,7 @@ def _make_line_label(signal_index, signal_labels, trace_index):
663665
new_title = old_title + separator + new_title[common_len:]
664666

665667
# Add the title
666-
with plt.rc_context(_timeplot_rcParams):
668+
with plt.rc_context(timeplot_rcParams):
667669
fig.suptitle(new_title)
668670

669671
return out

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy