Working with Plots

This example describes how to read / edit plot specifications, so that they can appear in the COPASI User Interface.

[1]:
import sys
if '../..' not in sys.path:
    sys.path.append('../..')
from basico import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

lets start with the Brusselator example, that we have in the examples

[2]:
load_example('brusselator');

now let us have a look at the plots defined in the file:

[3]:
get_plots()
[3]:
active log_x log_y tasks curves
name
Concentrations, Volumes, and Global Quantity Values True False False [{'name': '[X]', 'type': 'curve2d', 'channels'...
Phase Plot True False False [{'name': '[Y]|[X]', 'type': 'curve2d', 'chann...

To filter the plot specification, by name you can specify a substring to be used:

[4]:
get_plots('Phase Plot')
[4]:
active log_x log_y tasks curves
name
Phase Plot True False False [{'name': '[Y]|[X]', 'type': 'curve2d', 'chann...

the plot specification can also be retrieved directly as dictionary:

[5]:
get_plot_dict('Phase Plot')
[5]:
{'name': 'Phase Plot',
 'active': True,
 'log_x': False,
 'log_y': False,
 'tasks': '',
 'curves': [{'name': '[Y]|[X]',
   'type': 'curve2d',
   'channels': ['[X]', '[Y]'],
   'color': 'auto',
   'line_type': 'lines',
   'line_subtype': 'solid',
   'line_width': 2.0,
   'symbol': 'small_cross',
   'activity': 'during'}]}

Now let us add a new plot. Ensure to compare with :func:.set_plot_dict and :func:.set_plot_curves for all parameters. Note that the only parameters necessary for the curve are a name for the curve (which will be displayed in the legend), and the data channels of what information to collect. These channels again use the display names of the elements that you want to plot (so [X] for the concentration of species X).

[6]:
add_plot('test plot', curves=[{'name': 'x vs time', 'color': '#ff8800','channels':['Time', '[X]']}]);

and verify, that it is there and has gotten all the default values expected:

[7]:
get_plot_dict('test plot')
[7]:
{'name': 'test plot',
 'active': True,
 'log_x': False,
 'log_y': False,
 'tasks': '',
 'curves': [{'name': 'x vs time',
   'type': 'curve2d',
   'channels': ['Time', '[X]'],
   'color': '#ff8800',
   'line_type': 'lines',
   'line_subtype': 'solid',
   'line_width': 2.0,
   'symbol': 'small_cross',
   'activity': 'during'}]}

changing is possible as well, by using set_plot_dict directly.

finally the plot can also be deleted using remove_plot.

[8]:
remove_plot('test plot')