Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Cleaned up width and height arguments and docstrings for the plot spe…
…cies and plot property functions.
  • Loading branch information
BryanRumsey committed Jun 9, 2021
commit f11cbfed01541eec86c9c161509ac52b88654b18
53 changes: 30 additions & 23 deletions spatialpy/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,9 @@ def get_species(self, species, timepoints=None, concentration=False, determinist
ret = ret.flatten()
return ret

def plot_species(self, species, t_ndx=0, concentration=False, deterministic=False, width=500, height=500, colormap=None, size=5, title=None,
def plot_species(self, species, t_ndx=0, concentration=False, deterministic=False, width=None, height=None, colormap=None, size=5, title=None,
animated=False, t_ndx_list=None, speed=1, f_duration=500, t_duration=300, return_plotly_figure=False,
use_matplotlib=False, mpl_width=6.4, mpl_height=4.8,
debug=False):
use_matplotlib=False, debug=False):
""" Plots the Results using plotly. Can only be viewed in a Jupyter Notebook.

If concentration is False (default), the integer, raw, trajectory data is returned,
Expand Down Expand Up @@ -348,10 +347,6 @@ def plot_species(self, species, t_ndx=0, concentration=False, deterministic=Fals
which may be edited by the user.
use_matplotlib : bool
whether or not to plot the proprties results using matplotlib.
mpl_width: int (default 6.4)
Width in inches of output plot box
mpl_height: int (default 4.8)
Height in inches of output plot box
debug: bool
output debugging info
"""
Expand All @@ -373,6 +368,11 @@ def plot_species(self, species, t_ndx=0, concentration=False, deterministic=Fals
if use_matplotlib:
import matplotlib.pyplot as plt

if width is None:
width = 6.4
if height is None:
height = 4.8

if deterministic or not concentration:
d = data[spec_name]
else:
Expand All @@ -390,6 +390,11 @@ def plot_species(self, species, t_ndx=0, concentration=False, deterministic=Fals
plt.plot()
return

if width is None:
width = 500
if height is None:
height = 500

# map data to types
types = {}
for i, val in enumerate(data['type']):
Expand Down Expand Up @@ -549,15 +554,11 @@ def get_property(self, property_name, timepoints=None):
ret = ret.flatten()
return ret

def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500, colormap=None, size=5, title=None,
animated=False, t_ndx_list=None, speed=1, f_duration=500, t_duration=300, return_plotly_figure=False,
use_matplotlib=False, mpl_width=6.4, mpl_height=4.8):
""" Plots the Results using plotly. Can only be viewed in a Jupyter Notebook.

If concentration is False (default), the integer, raw, trajectory data is returned,
if set to True, the concentration (=copy_number/volume) is returned.

If deterministic is True, show results for determinstic (instead of stochastic) values
def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=None, height=None, colormap=None, size=5, title=None,
animated=False, t_ndx_list=None, speed=1, f_duration=500, t_duration=300,
return_plotly_figure=False, use_matplotlib=False):
"""
Plots the Results using plotly. Can only be viewed in a Jupyter Notebook.

Attributes
----------
Expand All @@ -568,9 +569,9 @@ def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500,
p_ndx : int
The property index of the results to be plotted
width: int (default 500)
Width in pixels of output plot box
Width in pixels of output plot box or for matplotlib inches of output plot box
height: int (default 500)
Height in pixels of output plot box
Height in pixels of output plot box or for matplotlib inches of output plot box
colormap : str
colormap to use. Plotly specification, valid values: "Plotly3","Jet","Blues","YlOrRd",
"PuRd","BuGn","YlOrBr","PuBuGn","BuPu","YlGnBu", "PuBu","GnBu","YlGn","Greens","Reds",
Expand All @@ -595,10 +596,6 @@ def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500,
which may be edited by the user.
use_matplotlib : bool
whether or not to plot the proprties results using matplotlib.
mpl_width: int (default 6.4)
Width in inches of output plot box
mpl_height: int (default 4.8)
Height in inches of output plot box
"""

if t_ndx < 0:
Expand All @@ -614,6 +611,11 @@ def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500,
if use_matplotlib:
import matplotlib.pyplot as plt

if width is None:
width = 6.4
if height is None:
height = 4.8

if property_name == 'v':
d = data[property_name]
d = [d[i][p_ndx] for i in range(0,len(d))]
Expand All @@ -622,7 +624,7 @@ def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500,
if colormap is None:
colormap = "viridis"

plt.figure(figsize=(mpl_width,mpl_height))
plt.figure(figsize=(width, height))
plt.scatter(points[:,0],points[:,1],c=d,cmap=colormap)
plt.axis('scaled')
plt.colorbar()
Expand All @@ -632,6 +634,11 @@ def plot_property(self, property_name, t_ndx=0, p_ndx=0, width=500, height=500,
plt.plot()
return

if width is None:
width = 500
if height is None:
height = 500

from plotly.offline import init_notebook_mode, iplot

types = {}
Expand Down