Skip to content

Plot included types list #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 18, 2021
Merged
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
30 changes: 23 additions & 7 deletions spatialpy/Domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def calculate_vol(self):


def plot_types(self, width=None, height=None, colormap=None, size=5, title=None,
use_matplotlib=False, return_plotly_figure=False):
included_types_list=None, use_matplotlib=False, return_plotly_figure=False):
'''
Plots the domain using plotly. Can only be viewed in a Jupyter Notebook.

Expand All @@ -339,6 +339,9 @@ def plot_types(self, width=None, height=None, colormap=None, size=5, title=None,
:param title: The title of the graph
:type title: str

:param included_types_list: A list of ints describing which types to include. By default displays all types.
:type included_types_list: list

:param return_plotly_figure: Whether or not to return a figure dictionary of data(graph object traces) and layout options
which may be edited by the user.
:type return_plotly_figure: bool
Expand All @@ -362,8 +365,20 @@ def plot_types(self, width=None, height=None, colormap=None, size=5, title=None,
if use_matplotlib:
import matplotlib.pyplot as plt

if included_types_list is None:
coords = self.vertices
type_list = self.type
else:
coords = []
type_list = []
for i, val in enumerate(self.type):
if val in included_types_list:
coords.append(self.vertices[i])
type_list.append(val)
coords = numpy.array(coords)

plt.figure(figsize=(width, height))
plt.scatter(self.vertices[:,0], self.vertices[:,1], c=self.type, cmap=colormap)
plt.scatter(coords[:,0], coords[:,1], c=type_list, cmap=colormap)
plt.axis('scaled')
plt.colorbar()
if title is not None:
Expand All @@ -378,11 +393,12 @@ def plot_types(self, width=None, height=None, colormap=None, size=5, title=None,
for i, val in enumerate(self.type):
name = "type {}".format(val)

if name in types.keys():
types[name]['points'].append(self.vertices[i])
types[name]['data'].append(self.type[i])
else:
types[name] = {"points":[self.vertices[i]], "data":[self.type[i]]}
if included_types_list is None or val in included_types_list:
if name in types.keys():
types[name]['points'].append(self.vertices[i])
types[name]['data'].append(self.type[i])
else:
types[name] = {"points":[self.vertices[i]], "data":[self.type[i]]}

is_2d = self.dimensions == 2

Expand Down
40 changes: 26 additions & 14 deletions spatialpy/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ def get_property(self, property_name, timepoints=None):

def plot_property(self, property_name, t_ndx=None, t_val=None, 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,
debug=False):
f_duration=500, t_duration=300, included_types_list=None, return_plotly_figure=False,
use_matplotlib=False, debug=False):
"""
Plots the Results using plotly. Can only be viewed in a Jupyter Notebook.

Expand Down Expand Up @@ -632,6 +632,8 @@ def plot_property(self, property_name, t_ndx=None, t_val=None, p_ndx=0, width=No
:type f_duration: int
:param t_duration: The duration of time to execute the transition between frames
:type t_duration: int
:param included_types_list: A list of ints describing which types to include. By default displays all types.
:type included_types_list: list
:param return_plotly_figure: whether or not to return a figure dictionary of data(graph object traces) and layout options
which may be edited by the user.
:type return_plotly_figure: bool
Expand Down Expand Up @@ -675,8 +677,16 @@ def plot_property(self, property_name, t_ndx=None, t_val=None, p_ndx=0, width=No
width = 6.4
if height is None:
height = 4.8

if property_name == 'v':

if property_name == "type" and included_types_list is not None:
coords = []
d = []
for i, val in enumerate(data[property_name]):
if val in included_types_list:
coords.append(points[i])
d.append(val)
points = numpy.array(coords)
elif property_name == 'v':
d = data[property_name]
d = [d[i][p_ndx] for i in range(0,len(d))]
else:
Expand Down Expand Up @@ -706,11 +716,12 @@ def plot_property(self, property_name, t_ndx=None, t_val=None, p_ndx=0, width=No
for i, val in enumerate(data['type']):
name = "type {}".format(val)

if name in types.keys():
types[name]['points'].append(points[i])
types[name]['data'].append(data[property_name][i])
else:
types[name] = {"points":[points[i]], "data":[data[property_name][i]]}
if included_types_list is None or val in included_types_list:
if name in types.keys():
types[name]['points'].append(points[i])
types[name]['data'].append(data[property_name][i])
else:
types[name] = {"points":[points[i]], "data":[data[property_name][i]]}
elif property_name == 'v':
types[property_name] = {
"points": points,
Expand Down Expand Up @@ -803,11 +814,12 @@ def plot_property(self, property_name, t_ndx=None, t_val=None, p_ndx=0, width=No
for i, val in enumerate(data['type']):
name = "type {}".format(val)

if name in types.keys():
types[name]['points'].append(points[i])
types[name]['data'].append(data[property_name][i])
else:
types[name] = {"points":[points[i]], "data":[data[property_name][i]]}
if included_types_list is None or val in included_types_list:
if name in types.keys():
types[name]['points'].append(points[i])
types[name]['data'].append(data[property_name][i])
else:
types[name] = {"points":[points[i]], "data":[data[property_name][i]]}
elif property_name == 'v':
types[property_name] = {
"points": points,
Expand Down