This page shows how to create 2D image plots of data from Lumerical's software using MATLAB.
MATLAB uses a different convention for plotting 2D matrix data than Lumerical. To get the same figure orientation in MATLAB as in your Lumerical plots, you must apply an unconjugated transpose operation and adjust the axes, as shown below.
2D image plot with uniform, rectilinear data
Lumerical image plot
x = 1:3; y = 1:4; A = [1,2,3,4;5,6,7,8;9,10,11,12]; matlabsave("toPlot.mat",x,y,A); image(x,y,A);
MATLAB commands to generate equivalent plot
load('toPlot.mat'); % transpose matrix, plot data, add color bar A2 = A.'; imagesc(x,y,A2); colorbar; % set axis limits set(gca,'Xlim',[min(x),max(x)]); set(gca,'Ylim',[min(y),max(y)]); % set Y axis direction set(gca,'YDir','normal');
2D image plot with non-uniform, rectilinear data
The standard image command in MATLAB assumes that matrix data is uniformly sampled, even when you provide the x,y position vectors. This is not true of the image command in the Lumerical script environment. This is an important detail when plotting data obtained from a non-uniform mesh. In the following example, notice that the Gaussian profile is not sampled uniformly in the Y direction. To plot this data in Matlab, you must interpolate the data on a uniform grid, as shown below.
Lumerical image plot
x = linspace(-1.5,0.5,100); y = [linspace(-2,0,20); linspace(0.01,1,100)]; X = meshgridx(x,y); Y = meshgridy(x,y); A = exp(-(1+3*X)^2-(0.5+Y)^2); matlabsave("toPlot.mat",x,y,A); image(x,y,A);
MATLAB commands to generate equivalent plot
load('toPlot.mat'); % create linearly spaced vectors x2 = linspace(min(x),max(x),200); y2 = linspace(min(y),max(y),200); % create 2D mesh grids. Note that X,y vectors are reversed, % as required by Matlab's different plotting convention [X,Y] = meshgrid(y,x); [X2,Y2] = meshgrid(y2,x2); % interpolate to new vectors A2 = interp2(X,Y,A,X2,Y2); % transpose matrix A3 = A2.'; % plot data, add color bar, set axis limits, set Y axis direction imagesc(x2,y2,A3); colorbar; set(gca,'Xlim',[min(x),max(x)]); set(gca,'Ylim',[min(y),max(y)]); set(gca,'YDir','normal');
Alternatively:
load('toPlot.mat'); A2=A.'; pcolor(x,y,A2); colorbar; shading interp;
See also
MATLAB - Lumerical integrations
Creating 2D image plots with MATLAB