From 7e24a7f4988f1abd64cbf5c4e2933480de1e57f1 Mon Sep 17 00:00:00 2001 From: Rob Falck Date: Fri, 19 Jan 2024 13:54:49 -0700 Subject: [PATCH] removed bare matplotlib imports in non-test source files. (#1035) --- .../brachistochrone/test/ex_brachistochrone.py | 5 ----- dymos/examples/cart_pole/animate_cartpole.py | 7 ++++--- dymos/examples/plotting.py | 5 ++--- dymos/visualization/timeseries_plots.py | 10 +++++----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/dymos/examples/brachistochrone/test/ex_brachistochrone.py b/dymos/examples/brachistochrone/test/ex_brachistochrone.py index 6b461377e..22368b248 100644 --- a/dymos/examples/brachistochrone/test/ex_brachistochrone.py +++ b/dymos/examples/brachistochrone/test/ex_brachistochrone.py @@ -1,4 +1,3 @@ -import matplotlib import numpy as np import openmdao.api as om @@ -8,10 +7,6 @@ from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE -SHOW_PLOTS = True -matplotlib.use('Agg') - - @require_pyoptsparse(optimizer='SLSQP') def brachistochrone_min_time(transcription='gauss-lobatto', num_segments=8, transcription_order=3, compressed=True, optimizer='SLSQP', run_driver=True, force_alloc_complex=False, diff --git a/dymos/examples/cart_pole/animate_cartpole.py b/dymos/examples/cart_pole/animate_cartpole.py index 90acf8f53..2021b4694 100644 --- a/dymos/examples/cart_pole/animate_cartpole.py +++ b/dymos/examples/cart_pole/animate_cartpole.py @@ -1,10 +1,11 @@ import numpy as np -import matplotlib.pyplot as plt -import matplotlib.patches as patches -from matplotlib import animation def animate_cartpole(x, theta, force, interval=20, force_scaler=0.1, save_gif=False, gif_fps=20): + + import matplotlib.pyplot as plt + import matplotlib.patches as patches + from matplotlib import animation # x: time history of cart location, 1d vector # theta: time history of pole angle, 1d vector # force: control input force diff --git a/dymos/examples/plotting.py b/dymos/examples/plotting.py index 301a3ba32..3cc73c829 100644 --- a/dymos/examples/plotting.py +++ b/dymos/examples/plotting.py @@ -1,6 +1,3 @@ -import matplotlib.pyplot as plt - - def plot_results(axes, title, figsize=(10, 8), p_sol=None, p_sim=None): """ Plot the timeseries results of a Dymos problem using matplotlib. @@ -22,6 +19,8 @@ def plot_results(axes, title, figsize=(10, 8), p_sol=None, p_sim=None): The Figure object and sequence of axes associated with the plot. """ + import matplotlib.pyplot as plt + nrows = len(axes) fig, axs = plt.subplots(nrows=nrows, ncols=1, figsize=figsize) diff --git a/dymos/visualization/timeseries_plots.py b/dymos/visualization/timeseries_plots.py index b85650d23..ec5c18707 100644 --- a/dymos/visualization/timeseries_plots.py +++ b/dymos/visualization/timeseries_plots.py @@ -4,11 +4,6 @@ import numpy as np -import matplotlib -import matplotlib.pyplot as plt -import matplotlib.lines as mlines -import matplotlib.patches as mpatches - import openmdao.api as om from .._options import options as dymos_options @@ -55,6 +50,11 @@ def _get_phases_node_in_problem_metadata(node, path=""): def _mpl_timeseries_plots(time_units, var_units, phase_names, phases_node_path, last_solution_case, last_simulation_case, plot_dir_path, dpi, include_parameters): + import matplotlib + import matplotlib.pyplot as plt + import matplotlib.lines as mlines + import matplotlib.patches as mpatches + # get ready to plot backend_save = plt.get_backend() plt.switch_backend('Agg')