Getting started
Plot a basic line graph
In this example we show how to use the Plots Python API functions in a standalone script to create a curve of the variables resulting from an Simcenter Amesim simulation.
When using the Simulation scripting functions, you can run a simulation, then load the results and get specific variables. This is typically done through the functions amerunsingle, ameloadt, and amegetvar.
The following piece of Python code illustrates the use of these functions:
Copy
# Post-processing the results
sysName = 'scrdemo'
Results, Varnames = ameloadt(sysName)
timeval, timelabel = amegetvar(Results, Varnames, 'time [s]')
name = amegetvarnamefromui(sysName, "theta@rotaryload2ports")[0]
rotangleval, rotanglelabel = amegetvar(Results, Varnames, name)
Here the time and the shaft angle are the two variables that are retrieved from the simulation results. You are going to plot the 2D curve of the rotangleval as a function of timeval.
Procedure
Create a new python file and save it as ameplot.py.This file is a new module where you can define different built-in graph display functions. In this example you only define the 2D line graph.The function is named plot2D and has as arguments the x values, y values, x label, and y label.
At this step the code is the following: Copy`import amepyplot
def plot2D(x,y,xlabel,ylabel):`
In the function plot2D you first create the plot widget PlotWidget(), set the plot window size using the function resize(), and access the generated graph using firstGraph().
Note Here there is only one graph on the plot window, however you can define a layout that contains several graphs on the same plot window.
At this step the code is the following: Copy`import amepyplot
def plot2D(x,y,xlabel,ylabel): plot = amepyplot.PlotWidget() plot.resize(800, 550) graph = plot.firstGraph()`
Next, you need to create the x and y items of the curve (using the Item object) and create the 2D curve that will be plotted (Curve2D).
Note The unit is already defined in the name of the variable, that's why the unit argument of the object Item is empty.
At this step the code is the following: Copy`import amepyplot
def plot2D(x, y, xlabel, ylabel): plot = amepyplot.PlotWidget() plot.resize(800, 550) graph = plot.firstGraph()
x_item = amepyplot.Item(x, xlabel, unit="")
y_item = amepyplot.Item(y, ylabel, unit="")
curve = amepyplot.Curve2D(x_item, y_item)`
The final step to fully define the function plot2D is to attach the curve to the graph and display the widget.
At this step the code is the following: Copy`import amepyplot
def plot2D(x, y, xlabel, ylabel): plot = amepyplot.PlotWidget() plot.resize(800, 550) graph = plot.firstGraph()
x_item = amepyplot.Item(x, xlabel, unit="")
y_item = amepyplot.Item(y, ylabel, unit="")
curve = amepyplot.Curve2D(x_item, y_item)
graph.addCurve(curve)
plot.show()
return plot`
Since the function to plot a 2D line graph is completed you just need to call it from your main script. Remember that you need to import the new module ameplot.
Copy`... import ameplot from PySide2 import QtWidgets
... ...
# Post-processing the results sysName = 'scrdemo' Results, Varnames = ameloadt(sysName) timeval, timelabel = amegetvar(Results, Varnames, 'time [s]') name = amegetvarnamefromui(sysName, "theta@rotaryload2ports")[0] rotangleval, rotanglelabel = amegetvar(Results, Varnames, name)
app = QtWidgets.QApplication.instance() if app is None: app = QtWidgets.QApplication([])
plot = ameplot.plot2D(timeval[0], rotangleval[0], timelabel[0], rotanglelabel[0]) app.exec_()`
Results
Using the Plots Python API you are able to display the results that are calculated from a standalone scripts. You can create the following curve for instance:
Figure 1: Simcenter Amesim plot window
Note
The function plot2D returns the plotWidget; you then have access to the graph for further customization.
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Plots_Python_API/xid1203341 · retrieved 2026-07-17