{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Working with Plots\n", "This example describes how to read / edit plot specifications, so that they can appear in the COPASI User Interface. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sys\n", "if '../..' not in sys.path:\n", " sys.path.append('../..')\n", "from basico import *\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "lets start with the Brusselator example, that we have in the examples" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "load_example('brusselator');" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "now let us have a look at the plots defined in the file:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
activelog_xlog_ytaskscurves
name
Concentrations, Volumes, and Global Quantity ValuesTrueFalseFalse[{'name': '[X]', 'type': 'curve2d', 'channels'...
Phase PlotTrueFalseFalse[{'name': '[Y]|[X]', 'type': 'curve2d', 'chann...
\n", "
" ], "text/plain": [ " active log_x log_y \\\n", "name \n", "Concentrations, Volumes, and Global Quantity Va... True False False \n", "Phase Plot True False False \n", "\n", " tasks \\\n", "name \n", "Concentrations, Volumes, and Global Quantity Va... \n", "Phase Plot \n", "\n", " curves \n", "name \n", "Concentrations, Volumes, and Global Quantity Va... [{'name': '[X]', 'type': 'curve2d', 'channels'... \n", "Phase Plot [{'name': '[Y]|[X]', 'type': 'curve2d', 'chann... " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_plots()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To filter the plot specification, by name you can specify a substring to be used: " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
activelog_xlog_ytaskscurves
name
Phase PlotTrueFalseFalse[{'name': '[Y]|[X]', 'type': 'curve2d', 'chann...
\n", "
" ], "text/plain": [ " active log_x log_y tasks \\\n", "name \n", "Phase Plot True False False \n", "\n", " curves \n", "name \n", "Phase Plot [{'name': '[Y]|[X]', 'type': 'curve2d', 'chann... " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_plots('Phase Plot')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "the plot specification can also be retrieved directly as dictionary:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'name': 'Phase Plot',\n", " 'active': True,\n", " 'log_x': False,\n", " 'log_y': False,\n", " 'tasks': '',\n", " 'curves': [{'name': '[Y]|[X]',\n", " 'type': 'curve2d',\n", " 'channels': ['[X]', '[Y]'],\n", " 'color': 'auto',\n", " 'line_type': 'lines',\n", " 'line_subtype': 'solid',\n", " 'line_width': 2.0,\n", " 'symbol': 'small_cross',\n", " 'activity': 'during'}]}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_plot_dict('Phase Plot')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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`). " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "add_plot('test plot', curves=[{'name': 'x vs time', 'color': '#ff8800','channels':['Time', '[X]']}]);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and verify, that it is there and has gotten all the default values expected:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'name': 'test plot',\n", " 'active': True,\n", " 'log_x': False,\n", " 'log_y': False,\n", " 'tasks': '',\n", " 'curves': [{'name': 'x vs time',\n", " 'type': 'curve2d',\n", " 'channels': ['Time', '[X]'],\n", " 'color': '#ff8800',\n", " 'line_type': 'lines',\n", " 'line_subtype': 'solid',\n", " 'line_width': 2.0,\n", " 'symbol': 'small_cross',\n", " 'activity': 'during'}]}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_plot_dict('test plot')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "changing is possible as well, by using `set_plot_dict` directly. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "finally the plot can also be deleted using `remove_plot`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "remove_plot('test plot')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }