Plotting in ASCEND
From ASCEND
You can generate x-y plots with ASCEND using both the PyGTK interface as well as the older (but no longer actively developed) Tcl/Tk interface.
There are two distinct ways to approach the problem of plotting in ASCEND. The first way is to use the models/plot.a4l ASCEND module to create a special plot sub-MODEL within you larger model. This model includes definition of data series, axis labels, etc, and ASCEND knows how to generate a plot from that sub-model once you have solved it. This approach is particularly suitable for plotting the solution of boundary-value problems, such as for the temperature profiles within a heat exchanger.
The other way is to solve your model repeatedly and store away selected data points, using either the STUDY command in the Tcl/Tk GUI, or the Observers functionality in the PyGTK GUI. This approach is suitable for parameter studies and for dynamic simulation results, where ASCEND does not keep a record of all the data points within the model structure.
Contents |
Plotting with 'plot.a4l'
Using this approach requires that you modify your model so that it includes the necessary 'plot' sub-model, which ASCEND can then use to access the required data for plotting.
An example that shows how a plot can be generated is given in models/plotbvp.a4c
Plots can include one or more curves on a single set of axes. You define the curves by composing arrays of points, then compose the plot by defining the set of curves. Curves can be labelled with integers (if you use plt_plot_integer) or with string-constant 'symbols' (if you use plt_plot_symbol).
Plotting via the PyGTK interface
To use plotting with the PyGTK interface, you must ensure you have numpy and matplotlib installed (these are Python modules that are available from standard Linux package repositories, and also as Windows installers). Then, when you load a model of the right type you can right-click on the sub-model element in the instance hierarchy (of type 'plt_plot_integer' or 'plt_plot_symbol', and click the 'Plot' option. You will get a plot window like so:
Plotting via the Tcl/Tk interface
To plot using the Tcl/Tk interface, you need to have a suitable xgraph program installed. See xgraph for details. The program needs to be in the location specified from the Script window, Tools → System utilities.
To test this, load the script separation_demos.a4s (File → Read file). Then execute the first two instructions:
DELETE TYPES; READ FILE "plotcol.a4c";
Then skip down to the instructions defining DemoPlotMacro and the eight lines following that solve a column model and produce plots from it.
All this worked just fine for me. I got nice plots with suitable labeling.
See also the Tcl/Tk screenshots.
Plotting in the PyGTK GUI using Observers
Because it is not always convenient (or even possible) to keep all of your calculation results present within your MODEL, the PyGTK GUI provides the Observers functionality. This allows you to record calculation values from your model on request, when using NLA solvers, or automatically, when using DAE solvers. The result is a table of values, which you can then plot.
Currently the interface for plotting from the Observer tab is a somewhat limited. However, you can get full access to the table data using the ASCEND Python Console, as shown in PyGTK Screenshots.
Alternatively, you can copy the table data using the menu, and paste the data into a spreadsheet program, then doing your plotting there.
If you have several columns in your observer data, use the following code in the Python console to plot the second and third columns:
O = browser.observers[0] O.plot(1,2) # ^^^ columns in our observer are numbered from zero import pylab pylab.xlabel("x axis") pylab.ylabel("y axis") pylab.title("plot title")
Plotting in the Tcl/Tk GUI using STUDY
There is information on how to do this in the ASCEND Manual, see Category:Documentation.


