diff --git a/ecell4/plotting/__init__.py b/ecell4/plotting/__init__.py index dbfaa9f5..d19cd0e2 100644 --- a/ecell4/plotting/__init__.py +++ b/ecell4/plotting/__init__.py @@ -46,15 +46,17 @@ def plot_number_observer(*args, backend=None, **kwargs): """ if backend == 'matplotlib': - _matplotlib.plot_number_observer(*args, **kwargs) + return _matplotlib.plot_number_observer(*args, **kwargs) elif backend == 'plotly': from . import _plotly - _plotly.plot_number_observer(*args, **kwargs) + return _plotly.plot_number_observer(*args, **kwargs) elif backend == 'elegans': from . import _elegans _elegans.plot_number_observer(*args, **kwargs) else: - BACKEND.plot_number_observer(*args, **kwargs) + ret = BACKEND.plot_number_observer(*args, **kwargs) + if ret is not None: + return ret def plot_world(*args, backend=None, **kwargs): """ @@ -75,15 +77,17 @@ def plot_world(*args, backend=None, **kwargs): """ if backend == 'matplotlib': - _matplotlib.plot_world(*args, **kwargs) + return _matplotlib.plot_world(*args, **kwargs) elif backend == 'plotly': from . import _plotly - _plotly.plot_world(*args, **kwargs) + return _plotly.plot_world(*args, **kwargs) elif backend == 'elegans': from . import _elegans _elegans.plot_world(*args, **kwargs) else: - BACKEND.plot_world(*args, **kwargs) + ret = BACKEND.plot_world(*args, **kwargs) + if ret is not None: + return ret def plot_movie(*args, backend=None, **kwargs): """ @@ -125,15 +129,17 @@ def plot_trajectory(*args, backend=None, **kwargs): """ if backend == 'matplotlib': - _matplotlib.plot_trajectory(*args, **kwargs) + return _matplotlib.plot_trajectory(*args, **kwargs) elif backend == 'plotly': from . import _plotly - _plotly.plot_trajectory(*args, **kwargs) + return _plotly.plot_trajectory(*args, **kwargs) elif backend == 'elegans': from . import _elegans _elegans.plot_trajectory(*args, **kwargs) else: - BACKEND.plot_trajectory(*args, **kwargs) + ret = BACKEND.plot_trajectory(*args, **kwargs) + if ret is not None: + return ret plot_movie_of_trajectory = _matplotlib.plot_movie_of_trajectory_with_matplotlib # default diff --git a/ecell4/plotting/_matplotlib.py b/ecell4/plotting/_matplotlib.py index 40af6750..70e21693 100644 --- a/ecell4/plotting/_matplotlib.py +++ b/ecell4/plotting/_matplotlib.py @@ -164,9 +164,10 @@ def plot_number_observer( ax.set_ylim(ylim) if filename is not None: - plt.savefig(filename) - else: - plt.show() + raise RuntimeError("filename was deprecated. Use the return value.") + # plt.savefig(filename) + plt.close() + return fig plot_number_observer_with_matplotlib = plot_number_observer @@ -274,7 +275,8 @@ def plot_world( legend_opts.update(legend) ax.legend(handles=plots, labels=species_list, **legend_opts) - plt.show() + plt.close() + return fig plot_world_with_matplotlib = plot_world @@ -331,7 +333,8 @@ def plot_trajectory( if isinstance(legend, dict): legend_opts.update(legend) ax.legend(**legend_opts) - plt.show() + plt.close() + return fig plot_trajectory_with_matplotlib = plot_trajectory @@ -438,7 +441,8 @@ def plot_trajectory2d_with_matplotlib( if isinstance(legend, dict): legend_opts.update(legend) ax.legend(**legend_opts) - plt.show() + plt.close() + return fig def plot_movie_of_trajectory2d_with_matplotlib( obs, plane='xy', figsize=6, grid=True, @@ -839,8 +843,8 @@ def plot_world2d_with_matplotlib( legend_opts.update(legend) ax.legend(**legend_opts) # ax.legend(handles=plots, labels=species_list, **legend_opts) - - plt.show() + plt.close() + return fig def __scatter_world2d_with_matplotlib( world, indices, ax, species_list, marker_size, max_count, scale, **kwargs): diff --git a/ecell4/plotting/_plotly.py b/ecell4/plotting/_plotly.py index d01b6bf7..d58bdba4 100644 --- a/ecell4/plotting/_plotly.py +++ b/ecell4/plotting/_plotly.py @@ -105,8 +105,7 @@ def plot_number_observer( if layout is not None: layout_.update(layout) fig.update(dict(layout=layout_)) - - plotly.offline.iplot(fig) + return fig plot_number_observer_with_plotly = plot_number_observer @@ -142,8 +141,7 @@ def plot_stl(filename, layout=None, **kwargs): layout_.update(layout) layout_ = go.Layout(**layout_) fig = go.Figure(data=[mesh3D], layout=layout_) - plotly.offline.iplot(fig) - + return fig def plot_world(world, species_list=None, max_count=1000, marker=None, layout=None, stl=None): """ @@ -215,7 +213,7 @@ def plot_world(world, species_list=None, max_count=1000, marker=None, layout=Non layout_.update(layout) layout_ = go.Layout(**layout_) fig = go.Figure(data=traces, layout=layout_) - plotly.offline.iplot(fig) + return fig plot_world_with_plotly = plot_world @@ -268,6 +266,6 @@ def plot_trajectory( layout_.update(layout) layout_ = go.Layout(**layout_) fig = go.Figure(data=traces, layout=layout_) - plotly.offline.iplot(fig) + return fig plot_trajectory_with_plotly = plot_trajectory