Plot 2D Gaussian spot and histograms of horizontal and vertical axis in one figure

9 次查看(过去 30 天)
I am simulating a spot of a Gaussian laser beam. I've added my simple code below. It creates three figures: one plot of the Gaussian spot itself, and two plots of the histograms of the vertical coordinates and horizontal coordinates. What I would like to do is create one figure with these three plots, with the histograms along their corresponding axes. I've added an example of this below that I created by combining the figures in MS Paint.
I would like to create this picture in MATLAB instead, does anyone know if this is possible? If yes, how?
Thank you in advance.
% Parameters of the Gaussian beam
M2 = 1.45; % M-squared, beam propagation factor
lambda = 800E-9; % Wavelength of the light [m]
w_init = 0.010; % Initial beam waist before the mirror [m]
sigma_pos = w_init/2; % Standard deviation of the initial Gaussian position distribution [m]
% Generating the random positions of 10000 light rays according to a
% Gaussian distribution
Nrays = 10000; % Number of rays
sigma_posy = sigma_pos/sqrt(2);
sigma_posz = sigma_posy;
qy0 = normrnd(0, sigma_posy, 1, Nrays);
qz0 = normrnd(0, sigma_posz, 1, Nrays);
% Plotting spot
figure()
box on
plot(qz0, qy0, 'b.')
xlabel('z [m]')
ylabel('y [m]')
axis square
%% Histogram plot
figure()
box on
histfit(sqrt(2)*qz0)
xlim([-0.015 0.015])
ylabel('Intensity')
figure()
box on
histfit(sqrt(2)*qy0)
xlim([-0.015 0.015])
ylabel('Intensity')

采纳的回答

Rohit Pappu
Rohit Pappu 2021-3-22
The above diagram can be created using subplot (for creating the grid of plots) and camroll (for rotating the histogram)
% Create a 3x3 subplot
% Z intensities
subplot(3,3,[1,2]);
box on
h1 = histfit(sqrt(2)*qz0)
xlim([-0.015 0.015])
ylabel('Intensity')
ax1 = h1.Parent;
set(ax1, 'xticklabel' ,[]);
% Plotting spot
subplot(3,3,[4 5 7 8]);
box on
f = plot(qz0, qy0, 'b.')
xlabel('z [m]')
ylabel('y [m]')
axis square
% Y intensities
subplot(3,3,[6 9])
box on
h2 = histfit(sqrt(2)*qy0)
xlim([-0.015 0.015])
ylabel('Intensity')
ax2 = h2.Parent;
camroll(ax2,-90) % Rotate the plot clockwise by 90 degrees
set(ax2, 'XTickLabel',[]);
  3 个评论
Rohit Pappu
Rohit Pappu 2021-3-22
编辑:Rohit Pappu 2021-3-22
Hi Floris, currently, there isn't any function to adjust the size of the graph. A workaround which I would suggest is to increase the subplot size from 3x3 to maybe like 10x10 and then play around with the position argument for each subplot. A higher grid size gives a finer control over the position of each subplot
Floris Wulf
Floris Wulf 2021-3-22
Ah OK, that explains it. I will use your proposed workaround, and I'll accept your answer. Thank you very much for your help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by