Skip to content

Commit

Permalink
Merge branch 'sedml-l1v4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
luciansmith authored Apr 30, 2021
2 parents cddac92 + 28ff920 commit 3e7cfb5
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 49 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ antimony>=2.12.0
sbml2matlab>=0.9.1
python-libsbml>=5.18.0
python-libnuml>=1.0.0
python-libsedml>=0.4.3
python-libsedml>=2.0.17
python-libcombine>=0.2.2
appdirs>=1.4.3
jinja2>=2.9.6
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# standards
'python-libsbml>=5.18.0',
'python-libnuml>=1.0.0',
'python-libsedml>=2.0.12',
'python-libsedml>=2.0.17',
'python-libcombine>=0.2.2',
# misc
'appdirs>=1.4.3',
Expand Down
22 changes: 21 additions & 1 deletion tellurium/plotting/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def save(self, filename, format):
:return:
"""

def addXYDataset(self, x_arr, y_arr, color=None, tag=None, name=None, filter=True, alpha=None, mode=None, logx=None, logy=None, scatter=None, error_y_pos=None, error_y_neg=None, showlegend=None, text=None, dash=None):
def addXYDataset(self, x_arr, y_arr, color=None, tag=None, name=None, filter=True, alpha=None, mode=None, logx=None, logy=None, scatter=None, error_y_pos=None, error_y_neg=None, showlegend=None, text=None, dash=None, linewidth=None, marker=None, mec=None, mfc=None, ms=None, mew=None, edgecolor=None, bottom=None, bartype=None, y2=None):
""" Adds an X/Y dataset to the plot.
:param x_arr: A numpy array describing the X datapoints. Should have the same size as y_arr.
Expand Down Expand Up @@ -297,6 +297,26 @@ def addXYDataset(self, x_arr, y_arr, color=None, tag=None, name=None, filter=Tru
dataset['text'] = text
if dash is not None:
dataset['dash'] = dash
if linewidth is not None:
dataset['linewidth'] = linewidth
if marker is not None:
dataset['marker'] = marker
if mec is not None:
dataset['mec'] = mec
if mfc is not None:
dataset['mfc'] = mfc
if ms is not None:
dataset['ms'] = ms
if mew is not None:
dataset['mew'] = mew
if edgecolor is not None:
dataset['edgecolor'] = edgecolor
if bottom is not None:
dataset['bottom'] = bottom
if bartype is not None:
dataset['bartype'] = bartype
if y2 is not None:
dataset['y2'] = y2
self.xy_datasets.append(dataset)

def getMergedTaggedDatasets(self):
Expand Down
73 changes: 51 additions & 22 deletions tellurium/plotting/engine_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,63 @@ def render(self):
fig, ax = plt.subplots(num=None, figsize=self.figsize, facecolor='w', edgecolor='k')
have_labels = False
show_legend = False # override self.use_legend if user called plot with showlegend=True
bartype = "vertical"
for dataset in self.getDatasets():
mode = "line"
kwargs = {}
if 'name' in dataset:
kwargs['label'] = dataset['name']
have_labels = True
if 'color' in dataset:
kwargs['color'] = dataset['color']
if 'alpha' in dataset and dataset['alpha'] is not None:
kwargs['alpha'] = dataset['alpha']
if 'showlegend' in dataset and dataset['showlegend'] is not None:
show_legend = dataset['showlegend']
if 'color' in dataset and dataset['color'] is not None:
kwargs['color'] = dataset['color']
scatter = False
marker = ''
if 'mode' in dataset and dataset['mode'] is not None:
if dataset['mode'] == 'markers':
scatter = True
marker = ''
if 'dash' in dataset and dataset['dash'] is not None:
kwargs['dashes'] = [4,2]
if "mode" in dataset:
mode = dataset["mode"]
#Set different defaults based on the mode
passkeys = ["alpha", "showlegend", "color", "linewidth", "marker", "mfc", "mec", "ms", "mew"]
if mode=="line":
kwargs['marker'] = ''
kwargs['linewidth'] = self.linewidth
elif mode=="markers":
kwargs['marker'] = 'o'
kwargs['linewidth'] = 0
passkeys = ["alpha", "showlegend", "color", "marker", "mfc", "mec", "ms", "mew"]
elif mode=="bar":
passkeys = ["alpha", "showlegend", "color", "linewidth", "edgecolor", "bottom"]
elif mode=="fillBetween":
passkeys = ["alpha", "showlegend", "color", "y2"]
for dkey in dataset:
element = dataset[dkey]
if element is None:
continue
#These keys have the same id as is needed in the matplotlib call
if dkey in passkeys:
kwargs[dkey] = element

#These keys must be translated to matplotlib
elif dkey=="name":
kwargs['label'] = element
have_labels = True
elif dkey=="bartype":
bartype = element
elif dkey == 'dash' and mode != "bar":
if isinstance(dataset['dash'], list):
kwargs['dashes'] = element
else:
kwargs['dashes'] = [4,2]


if 'text' in dataset and dataset['text'] is not None:
for x,y,t in zip(dataset['x'], dataset['y'], dataset['text']):
plt.text(x, y, t, bbox=dict(facecolor='white', alpha=1))
elif not scatter:
plt.plot(dataset['x'], dataset['y'], marker=marker, linewidth=self.linewidth, **kwargs)
elif mode == "fill":
plt.fill_between(dataset['x'], dataset['y'], **kwargs)
elif mode == "fillBetween":
plt.fill_between(dataset['x'], dataset['y'], **kwargs)
elif mode == "bar":
if bartype == "horizontal":
if "bottom" in kwargs:
kwargs["left"] = kwargs["bottom"]
del kwargs["bottom"]
plt.barh(dataset['x'], dataset['y'], **kwargs)
else:
plt.bar(dataset['x'], dataset['y'], **kwargs)
else:
plt.scatter(dataset['x'], dataset['y'], **kwargs)
plt.plot(dataset['x'], dataset['y'], **kwargs)

# TODO: data as points

Expand Down
Loading

0 comments on commit 3e7cfb5

Please sign in to comment.