필터 지우기
필터 지우기

How to set the same grid size of the axis for different plots?

조회 수: 12 (최근 30일)
Using imagesc function, I plotted the data for different sets of vaues. For the first plot, the x-axis limits are [-40 12] and for the second plot, the x-axis limits are [-56 8]. But I got the same size of the the plots. How to get the different size of the plots using an equal grid size for both the plots?
If I add the colorbar the size of the second image plot shrinks. How to add the colorbar without affecting the size of the image?
  댓글 수: 2
KSSV
KSSV 2023년 1월 30일
Show us your code.
Sateesh Kandukuri
Sateesh Kandukuri 2023년 1월 30일
allTables = dir('**/table.txt');
%first loop for sorting the folders by sorting the files
for k = 1:numel(allTables)
F1 = fullfile(allTables(k).folder, allTables(k).name);
A1 = readmatrix(F1);
% sort files
I = max(A1(:,11));
allTables(k).max= I;
end
[~,X] = sort([allTables.max]);
allTables = allTables(X);
%normal modes
Bmin= -40;
Bmax= 12;
Bstep= 4;
T=20; % Total run time in ns
basicf=10000/20;
resolf=1e-9/T;
matrixplot=zeros(20001,k);
for index = 1:numel(allTables)
F2 = fullfile(allTables(index).folder, allTables(index).name);
A2 = readmatrix(F2);
M=A2(:,4);
M=M-mean(M);
sol=fft(M);
sol2=fftshift(sol);
maxpeax=max(abs(sol2));
sol3=abs(sol2)/maxpeax;
matrixplot(1:length(sol),index)=sol3;
end
x=[Bmin Bmax];
y=[-basicf basicf];
imagesc(x,y,matrixplot);
xlim([Bmin Bmax]);
ylim([0 08]);
set(gca,'Ydir','normal','FontSize',16)
ylabel('f (GHz)', 'FontSize', 20, 'FontWeight', 'bold');
xlabel('B_z(mT)', 'FontSize', 20, 'FontWeight', 'bold');
txt = {'B_z , m_z'};
text(0,7,txt,'FontSize', 16, 'Color','w')

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 30일
편집: Walter Roberson 2023년 2월 2일
You can set the plot box aspect ratio and data aspect ratio, or use the convenience of "axis image" https://www.mathworks.com/help/matlab/ref/axis.html#d124e70500
image objects fill at least one dimension of the axes, so if you need the drawing area to have the same pixel size for multiple axes, then you might need to set the axes Units to pixels and set the Position to the desired image size in pixels (make sure that you "axis off")
You can set the colorbar Position in pixels
  댓글 수: 1
Sateesh Kandukuri
Sateesh Kandukuri 2023년 1월 31일
편집: Sateesh Kandukuri 2023년 1월 31일
Dear Walter Roberson, thank you so much for your response. I solved my problem in another way.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by