Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pymoo/core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ def __init__(self,
# change the font of plots to serif (looks better)
plt.rc('font', family='serif')

# the matplotlib classes
# the matplotlib classes — publicly accessible after do()/show()/save()
# you can also use get_figure() and get_axes() helper methods
self.fig = fig
self.ax = ax
self.figsize = figsize

# whether the figure should be closed when object is destroyed
# set to False if you want to keep the figure alive after the Plot object
# goes out of scope (e.g. to further customise or display it)
self.close_on_destroy = close_on_destroy

# the title of the figure - can also be a list if subfigures
Expand Down Expand Up @@ -172,10 +175,19 @@ def show(self, **kwargs):
# in a notebook the plot method need not to be called explicitly
if not in_notebook() and matplotlib.get_backend().lower() != "agg":
plt.show(**kwargs)
plt.close()
# NOTE: plt.close() removed — callers can now close the figure themselves
# if needed, e.g.: plot.fig.savefig(...); plt.close(plot.fig)

return self

def get_figure(self):
self.plot_if_not_done_yet()
return self.fig

def get_axes(self):
self.plot_if_not_done_yet()
return self.ax

def save(self, fname, **kwargs):
self.plot_if_not_done_yet()
set_if_none(kwargs, "bbox_inches", "tight")
Expand Down