This video is taken from the Scripting Learning Track on Ansys Innovation Courses.
Once you retrieve the data of your interest, you can use various plotting commands to visualize
plot and plotxy for line plots, polar and polar2 for polar plot, image for 2d color
plot, and polarimage for 2d polar color plot.
We are going to have a close look at each of these and some other useful plotting commands
in the next slides.
Plot command creates a line plot.
All data sets in its argument should be sampled on the same position vector.
In this example, we have a linearly spaced vector array x, and y1 and y2 are sine and
cosine of x, respectively.
To plot y1 as a function of x, you can use plot with arguments x and y1.
You can add the label for axis and the title.
You can create multiple lines on the same plot as long as all the y vectors have the
same length and are sampled on the same x position vector.
In order to distinguish the multiple lines, you can add a legend for each line using the
Unlike the plot command, plotxy allows you to use datasets that are sampled on different
Here we have x1, y1 and x2, y2 vectors with different sampling positions.
To create both curves on a same plot, use plotxy and enter the corresponding vector
If you want to visualize your results in polar coordinates, you can use 'polar'.
Like 'plot', all data sets must be sampled on the same array of angle values.
It takes the angle and the radius as its arguments.
Here's an example of multiple plots using same theta values.
Similar to plotxy, you can add multiple polar plots sampled on different angle values using
the 'polar2' command.
In this example, theta1 is an array of 30 points from 0 to 2*pi and theta2 is an array
with 10 points from 0 to pi.
To create the multiple plots sampled on different angle values, enter each matching pair of
angle and radius as the arguments of the polar2.
So far we have learned about various line plot commands.
To create 2d color plots, you can use the 'image' command.
In this example, the lower case x and y correspond to the data points in the x and y axis.
The upper case X and Y are the meshgrid points in x- and y-direction.
Z is a 2d matrix containing the values for each meshgrid point.
To create an image of Z in terms of x and y, enter the x and y vectors and Z as its
Polarimage creates 2D polar image plots.
This is typically used to plot far field data.
It takes at least three arguments ux, uy and data.
Unlike the 'image' command, the first two arguments should be a vector that can go from
-1 to +1.
When used with farfield projection commands, ux and uy are associated with the direction
cosine of the farfield - hence the limitations on the values they can accept.
This example generates an image of a 2d Gaussian function in polar coordinates.
When compared with the 'image' command, you can see that the region where the abs(ux)^2
+abs(uy)^2 is larger than '1' is clipped in the polarimage.
The plotting commands introduced so far allow you to use an additional argument with ¡®options¡¯
for enhanced visualization.
For example, in the 'plot' command, you can customize the plot type, color and marker
For further details about the acceptable parameters and their values for each command, please
refer to the corresponding scripting page in the Knowledge Base.
You can set additional properties of a plot using the 'setplot' command.
If you are not sure about the names of the properties, use a question mark before setplot
. Then, all the available plot properties associated with the current plot will be displayed
in the script prompt.
The following script will set the title of the plot.
Here are some other plotting commands you might find useful.
As we have already seen in the previous slides, legend adds a legend to a line plot.
Holdon switches the plotting mode to hold multiple functions on the same figure.
Holdoff switches off the holdon mode.
'selectfigure' selects a figure with a specified figure number.
When used without any argument, it selects the last figure created.
'exportfigure' exports the current figure to a JPG image with the name 'filename'.
The exported image will have the specified resolution, xres,yres, in the x,y directions
If the x/y resolutions are not specified, the exported image will have the same size
as the current figure.