Skip to content

Commit

Permalink
removed bare matplotlib imports in non-test source files. (OpenMDAO#1035
Browse files Browse the repository at this point in the history
)
  • Loading branch information
robfalck authored Jan 19, 2024
1 parent 8bb2226 commit 7e24a7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
5 changes: 0 additions & 5 deletions dymos/examples/brachistochrone/test/ex_brachistochrone.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import matplotlib
import numpy as np

import openmdao.api as om
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions dymos/examples/cart_pole/animate_cartpole.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions dymos/examples/plotting.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions dymos/visualization/timeseries_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 7e24a7f

Please sign in to comment.