Skip to content

Commit

Permalink
Add show_plot option for Solution.plot()
Browse files Browse the repository at this point in the history
  • Loading branch information
c-randall committed Dec 26, 2024
1 parent 87cdd07 commit e9245f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/thevenin/_solutions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations
from typing import Iterable, TYPE_CHECKING

import atexit
import textwrap
from copy import deepcopy

import atexit
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import cumulative_trapezoid
Expand Down Expand Up @@ -74,7 +74,7 @@ def wrap_string(label: str, value: list, width: int):

return readable

def plot(self, x: str, y: str, **kwargs) -> None:
def plot(self, x: str, y: str, show_plot: bool = True, **kwargs) -> None:
"""
Plot any two variables in 'vars' against each other.
Expand All @@ -84,6 +84,10 @@ def plot(self, x: str, y: str, **kwargs) -> None:
A variable key in 'vars' to be used for the x-axis.
y : str
A variable key in 'vars' to be used for the y-axis.
show_plot : bool, optional
For non-interactive environments only. When True (default) this
registers `plt.show()` to run at the end of the program. If False,
you must call `plt.show()` manually.
Returns
-------
Expand All @@ -109,7 +113,8 @@ def plot(self, x: str, y: str, **kwargs) -> None:
plt.xlabel(xlabel)
plt.ylabel(ylabel)

atexit.register(plt.show)
if show_plot and not plt.isinteractive():
atexit.register(plt.show)

def _to_dict(self) -> None:
"""
Expand Down

0 comments on commit e9245f7

Please sign in to comment.