Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 15 additions & 9 deletions ecell4/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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

Expand Down
20 changes: 12 additions & 8 deletions ecell4/plotting/_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 4 additions & 6 deletions ecell4/plotting/_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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