Skip to content

Commit

Permalink
add filename argument to save the eigenvalues plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mtezzele committed Apr 19, 2021
1 parent 5f0ff06 commit b17710d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pydmd/dmdbase.py
Expand Up @@ -382,7 +382,8 @@ def plot_eigs(self,
figsize=(8, 8),
title='',
narrow_view=False,
dpi=None):
dpi=None,
filename=None):
"""
Plot the eigenvalues.
:param bool show_axes: if True, the axes will be showed in the plot.
Expand All @@ -396,6 +397,7 @@ def plot_eigs(self,
rectangular area which contains all the eigenvalues, with a padding
of 0.05. Not compatible with `show_axes=True`. Default is False.
:param dpi int: If not None, the given value is passed to ``plt.figure``.
:param str filename: if specified, the plot is saved at `filename`.
"""
if self.eigs is None:
raise ValueError('The eigenvalues have not been computed.'
Expand Down Expand Up @@ -471,7 +473,10 @@ def plot_eigs(self,

ax.set_aspect('equal')

plt.show()
if filename:
plt.savefig(filename)
else:
plt.show()

def plot_modes_2D(self,
index_mode=None,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_dmd.py
Expand Up @@ -181,6 +181,12 @@ def test_plot_eigs_2(self):
dmd.plot_eigs(show_axes=False, show_unit_circle=False)
plt.close()

def test_plot_eigs_3(self):
dmd = DMD()
dmd.fit(X=sample_data)
dmd.plot_eigs(show_axes=False, show_unit_circle=True, filename='eigs.png')
self.addCleanup(os.remove, 'eigs.png')

def test_plot_modes_1(self):
dmd = DMD()
dmd.fit(X=sample_data)
Expand Down

0 comments on commit b17710d

Please sign in to comment.