Plotting functions
plot - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates line plots. All data sets must be sampled on the same position vector.
See plotxy for data sets that are sampled on different position vectors.
Syntax | Description |
---|---|
out = plot(x,y); | Creates a plot of y vs x, y and x are both 1D vectors with the same length. The figure number is returned. |
plot(x,y); | x is a nx1 matrix. y is a nxm matrix. This will generate a graph with m lines. (y(1:n,1) vs x, y(1:n,2) vs x, etc) |
plot(x,y1,y2,y3); | Creates a plot with 3 curves, x,y1, y2, y3 must be the same length, returns the figure number. |
plot(x,y, "x label", "y label", "title"); | Creates a plot of y vs x with axis labels and a title, returns the figure number. |
plot(x,y, "x label", "y label", "title", "options"); | Creates a plot with desired options. Options are listed in the table below. Returns the figure number. |
Plot options. May include multiple plot options in a single string, such as
"plot type=line, color=blue, pen=--, linewidth=2"
plot type | line point bar |
marker style | x o + s (square) d (diamond) |
pen | -- : -. -.. |
x axis location | top bottom |
y axis location | left right |
color | blue red etc. |
greyscale | |
plot lines | |
plot bar | |
plot points | |
marker size (default=4) | # |
linewidth (default=1) | # |
Examples
This example will generate a figure with two lines: sin(x) and (sin(x))^2.
x=linspace(0,10,100); y1=sin(x); y2=y1^2; plot(x,y1,y2,"x","y","title"); legend("sin(x)", "sin(x)^2");
The following figure shows the output of the the example code.
This example will generate a figure with two lines: sin(x) and sin(x)^2 with more plotting options.
x=linspace(0,10,100); y1=sin(x); y2=y1^2; plot(x,y1,"x","y","title", "plot type=line, color=red, pen=-., linewidth=2"); holdon; plot(x,y2,"x","y","title", "plot type=line, color=blue, pen=--, linewidth=2"); legend("sin(x)", "sin(x)^2");
The following figure shows the output of the the example code.
plotxy - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates line plots. In particular, this function is used when the data sets are sampled on different position vectors.
Syntax | Description |
---|---|
out = plotxy(x,y); | Creates a plot of y vs x, y and x are both 1D vectors with the same length. The figure number is returned. |
plotxy(x1,y1,x2,y2,xn,yn); | Creates a plot with multiple curves. The xn-yn pairs must have the same length, but x1, x2, and xn can have different start-end values and resolutions. The figure number is returned. |
plotxy(x1,y1,x2,y2, "x label", "y label", "title"); | Creates line plots with axis labels and a title, returns the figure number. |
Example
This example will generate a figure with two functions with different resolutions:
x1=linspace(0,2*pi,15); y1=sin(x1); x2=linspace(1,pi,3); y2=x2/2; plotxy(x1,y1,x2,y2,"x","y","title"); legend("y1=sin(x1) - 15 pts","y2=x2/2 - 3 pts");
The following figure shows the output of the the example code.
polar - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates polar plots. All data sets must be sampled on the same array of angle values.
See polar2 for data sets that are sampled on different arrays of theta values.
Syntax | Description |
---|---|
out = polar(theta,rho) | Creates a polar coordinate plot of the angle theta versus the radius rho. theta is the angle from the x-axis to the radius vector specified in radians; rho is the length of the radius vector. Theta and rho can be vectors of the same length, or if the length of theta is n, then rho can be a nxm matrix, which corresponds to m sets of rho values. The figure number is returned. |
polar(theta,rho1,rho2,rho3) | Creates a polar plot with three curves. theta, rho1, rho2, rho3 must be of the same length. The figure number is returned. |
polar(theta,rho,"x label", "y label", "title") | Creates a polar plot with axis labels and a title. The figure number is returned. |
polar(theta,rho,"x label", "y label", "title", "options"); | Creates a polar plot with desired options. Options can be be
Returns the figure number. |
Example
Create a simple polar plot.
theta = linspace(0,2*pi,100); r = cos(theta); polar(theta,r);
The following figure shows the output of the the example code.
polar2 - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates polar plots. In particular, this function is used when the data sets are sampled on different arrays of angle values.
Syntax | Description |
---|---|
out = polar2(theta,rho) | Creates a polar coordinate plot of the angle theta versus the radius rho. theta is the angle from the x-axis to the radius vector specified in radians; rho is the length of the radius vector. Theta and rho can be vectors of the same length, or if the length of theta is n, then rho can be a nxm matrix, which corresponds to m sets of rho values. The figure number is returned. |
polar2(theta1,rho1,theta2,rho2) | Creates a plot with two curves. The two data sets can be sampled on different theta vectors. |
polar2(theta,rho,"x label", "y label", "title") | Creates a plot of y vs x with axis labels and a title, returns the figure number. |
polar2(theta,rho,"x label", "y label", "title", "options"); | Creates a plot with desired options. Options can be be
Returns the figure number. |
Example
Plot in polar coordinates two different data sets.
theta1 = linspace(0,2*pi,100); r1 = cos(theta1); theta2 = linspace(0,pi,50); r2 = sin(theta2); polar2(theta1,r1,theta2,r2);
The following figure shows the output of the the example code.
polarimage - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates 2D polar image plots. This is typically used to plot far field data.
Syntax | Description |
---|---|
polarimage(ux,uy,data); | Creates a 2D image plot. data must be of dimension N x M and
|
out = polarimage(ux,uy,data, "x label", "y label", "title"); | Creates a 2D image plot with axis labels Optionally returns the figure number. |
polarimage(ux,uy,data, "x label", "y label", "title", "options"); | Creates a 2D image plot with axis labels and options, options can be
|
Example
This example generates an image of a simple 2D Gaussian function.
ux=linspace(-1,1,51); uy=linspace(-1,1,61); Ux=meshgridx(ux,uy); Uy=meshgridy(ux,uy); data = exp( 1-Ux^2-Uy^2); # plot data with both the image and polarimage script functions image(ux,uy,data,"ux","uy","Image plot"); polarimage(ux,uy,data,"ux","uy","Polar Image plot");
The following figure shows the resulting figures.
This example shows how this function might be used with the far field projection functions.
m="monitor1"; # monitor name ux=farfieldux(m); # position vectors uy=farfielduy(m); E2=farfield3d(m); # Far field E2 data polarimage(ux,uy,E2,"ux","uy","far field |E|^2");
smithchart - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Plots impedance values in a Smith chart. The default impedance used for normalization is 50 Ohms; this can be modified in the plot settings once the plot has been created.
Syntax | Description |
---|---|
out = smithchart(Z); | Creates a curve in a Smith chart with the impedance values in the array Z. The array Z must be of the form NX1 or 1XN. |
out = smithchart(Z1,Z2,Z3); | Creates three curves in a Smith chart with the impedance values in the arrays Z1, Z2 and Z3. Each array must be of the form NX1 or 1XN, but they do not have to be of the same dimension. |
out = smithchart(Z, "title", "aspect ratio", norm_Z); | Creates a Smith chart with a title, a given aspect ratio and a normalized impedance norm_Z. The aspect ratio must be string that is either "1:1" or "fill scene". |
Example
Create a simple Smith chart
Z1 = 50*(3+1i*linspace(-50,50,101)); # re(Z) = 3 circle Z2 = 50*(linspace(0,50,101)+0.75i); # im(Z) = 0.75 line smithchart(Z1,Z2,"Example of Smith chart", "1:1", 50); # Normalized impedance 50 Ohms #The plot properties can also be set using setplot: smithchart(Z1,Z2); setplot("title", "Example of Smith chart"); setplot("aspect ratio", "1:1"); setplot("normalized impedance", 50);
The following figure shows the output of the example code.
histc - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates a histogram plot.
Syntax | Description |
---|---|
out = histc(y); | Creates a histogram plot of y. Returns the figure number. |
histc(y,n); | Creates a histogram plot of y, using n bins. Returns the figure number. |
histc (y,n, "x label", "y label", "title"); | Creates a histogram plot of y, using n bins, with axis labels and a title. Returns the figure number. |
Example
These are scripts for creating simple histograms.
#Creates a histogram plot of y. y = randmatrix(1,10); y = y*10; out = histc(y); #Creates a histogram plot of y, using n bins. #Returns the figure number. y = randmatrix(1,10); y = y*10; n = 5; out = histc(y,n); #Creates a histogram plot of y, using n bins, with axis labels and a title. histc (y,n, "x label", "y label", "title");
bar - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Plots a bar chart.
Syntax | Description |
---|---|
out = bar(y); | Creates a bar plot where each bar corresponds to one element in y, which must be a 1D array. The figure number is returned. |
bar(x,y); | x is a nx1 matrix. y is a nxm matrix. Creates m bar plots with n bars in the same figure for the elements in y at positions given by x. The figure number is returned. |
bar(x,y, "x label", "y label", "title"); | Creates a bar plot of y vs x with axis labels and a title, returns the figure number. The figure number is returned. |
Examples
The following example generates the two bar plots shown below.
x = linspace(0,1,10); y1 = exp(-((x-0.2)/0.4)^2); y2 = exp(-((x-0.7)/0.3)^2); y = [y1,y2]; bar(y1); # bar plot for y1, where each bar is labeled from 1 to 10 bar(x,y); # bar plot for y1 and y2 at locations specified by x
| |
legend - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Adds a legend to a line plot.
Syntax | Description |
---|---|
legend("legend1","legend2",..., "legendn"); | Adds a legend to the selected figure. Parameters can be strings, or an array (cell) of strings This function does not return any data. |
Example
Add a legend using an array of strings.
x=linspace(0,10,100); y1=sin(x); y2=y1^2; plot(x,y1,y2,"x","y","title"); # create an array of strings leg=cell(2); leg{1}="y1"; leg{2}="y2"; # add legend legend(leg);
Using a for loop to add a number to the legend.
n=5; # number of legend leg=cell(n); # define the array of strings y=linspace(10,50,n); for (i=1:n){ leg{i}=num2str(y(i)); } # add legend legend(leg);
image - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates 2D image plots.
Syntax | Description |
---|---|
out = image(x,y,z); | Creates a 2D image plot of the data in z. If x is of dimension N x 1 and y is of dimension M x 1, then z must be of dimension N x M. The figure number is returned. |
image(x,y,z, "x label", "y label", "title"); | Creates a 2D image plot with axis labels and a title. The figure number is returned. |
image(x,y,z, "x label", "y label", "title", "options"); | Creates a 2D image plot with axis labels and options, options can be
|
Example
This example generates a figure of the 2D function pic(x,y)=sin(x)+sin(y).
x=linspace(0,10,100); y=linspace(0,10,100); x2=sin(x); y2=sin(y); pic=meshgridx(x2,y2)+meshgridy(x2,y2); image(x,y,pic,"","","","logplot"); image(x,y,pic,"","","","logplot,red2blue");
The following figures show the output of the example code.
setplot - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Sets the plot properties of a figure.
Syntax | Description |
---|---|
?setplot; | Creates a string which lists all figure properties for the figure that is currently selected. Unless the selectfigure() command was called, the most recently created plot will be selected. |
setplot("property", "property value"); | Set the desired property of the currently selected figure to property value. |
Example
This example uses the script command setplot to see the properties of a line plot figure, then adds a title to the figure.
plot(1:10,(1:10)^2); ?setplot; x min x max y min y max title x label y label legend position setplot("title","my figure"); #add a title to the figure
This example creates an image plot of a 10x10 matrix of random numbers between zero and one, then sets the color bar limits to 0.2 - 0.8 with the setplot command.
data=randmatrix(10,10); image(1:10,1:10,data); setplot("colorbar min",0.2); setplot("colorbar max",0.8);
visualize - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Sends data to the visualizer.
For FDTD, MODE, DGTD, FEEM, CHARGE, HEAT, and INTERCONNECT
Syntax | Description |
---|---|
visualize(R); | Plots the dataset R in the Visualizer. |
visualize(R,T); | Sends two datasets to the Visualizer. |
Example
This example creates a 3D dataset of random numbers and plots it in the visualizer. An additional dataset is created and added to the visualizer using add2visualizer.
nPts=10; axis=1:nPts; data=randmatrix(nPts,nPts,nPts); dataset = rectilineardataset("dataset",axis,axis,axis); dataset.addattribute("data",data); visualize(dataset); dataset2 = rectilineardataset("dataset2",axis,axis,axis); dataset2.addattribute("data",data+10); add2visualizer(dataset2, 1);
add2visualizer - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Adds data to an existing visualizer.
Syntax | Description |
---|---|
add2visualizer( dataset, visualizer number ) | This command adds data to an existing visualizer. If there is no visualizer corresponding to the visualizer number, then the command is ignored. |
Example
See example for visualize command.
vectorplot - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Creates a vector plot from a rectilinear dataset. The rectilinear dataset must be a vector, like the E field, and it must have no additional parameters (i.e., if you have E vs. x,y,z,f and f has two or more values, then the command fails). Generally, it is easier to use visualize(E) and then select the vector plot option in the visualizer.
Syntax | Description |
---|---|
vectorplot(E); | Creates a vector plot of the dataset |
Example
This example will generate a vector plot of the dataset E.
x = linspace(-1,1,10); y = x; z = x; X = meshgrid3dx(x,y,z); Y = meshgrid3dy(x,y,z); Z = meshgrid3dz(x,y,z); Ex = exp( -X^2-Y^2-Z^2); Ey = 0*Ex; Ez = 0*Ex; E = rectilineardataset("E",x,y,z); E.addattribute("E",Ex,Ey,Ez); vectorplot(E);
The following figure shows the output of the the example code.
holdon - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Holds multiple functions on a single plot. Note that, only the labeling and plot options of the first plot are taken into account; a warning is reported in this case. The command setplot can be used instead.
Syntax | Description |
---|---|
holdon; | Switches on the mode to hold multiple mathematical functions on the same figure. |
Example
This example will generate a figure with three lines based on the sin(x) function.
# setup data # for logarithm, avoid non-positive values x1=linspace(1,10,100); x2=linspace(2,11,100); y1=sin(x1)+1.1; y2=y1^2+1.1; # plot y1, y2, y3 plot(x1,y1,"x","y","holdon/off","log10x"); holdon; plot(x2,y2,"xx","yy","title1","log10y, plot points"); plot(x2,2*y2, "xxx","yyy", "title2", "greyscale"); # plot labeling and options cannot work in hold on # use setplot command instead! legend("y1","y2","y3"); holdoff;
The following figure shows the output of the the example code.
holdoff - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Switches off the holdon mode.
Syntax | Description |
---|---|
holdoff; | Switches off the mode to hold multiple mathematical functions on the same figure. |
Example
An example is available on the holdon page.
Miscellaneous plotting functions
selectfigure - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Selects a figure, which will be shown on screen (gives it focus). A warning will be generated if the figure does not exist.
Syntax | Description |
---|---|
selectfigure; | Selects the last figure that was created. This function does not return any data. |
selectfigure(1); | Selects figure 1. |
Example
See exportfigure example.
exportfigure - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Exports the current figure to a JPG image. If the file extension is not specified, ".jpg" will be used. The image size will be the same as the figure window size.
If a file is overwritten or if the export fails, a warning will be generated.
Syntax | Description |
---|---|
exportfigure("filename"); | Exports the current figure to a JPG image with the name "filename". The exported image will have the same size as the current figure. |
exportfigure("filename",xres,yres); | The exported image will have the specified resolution, xres,yres, in the x,y directions respectively. |
Example
Create two figures, then select the first and export it to a .jpg file. All the previously opened figure windows are closed beforehand using closeall.
closeall; x=linspace(0,10,100); y1=sin(x); y2=y1^2; plot(x,y1,"x","y","title"); plot(x,y2,"x","y","title"); selectfigure(1); exportfigure("sine.jpg");
closeall - Script command
FDTD MODE DGTD CHARGE HEAT FEEM INTERCONNECT
Closes all open figure windows.
Syntax | Description |
---|---|
closeall; | Close all open figure windows. This function does not return any data. |
Example
See exportfigure example.