I am using contour with a color bar. The axis are not equal sizes.

6 ビュー (過去 30 日間)
Erik Hoberg
Erik Hoberg 2020 年 10 月 6 日
コメント済み: Erik Hoberg 2020 年 10 月 13 日
figure
%plotting the contour
contourf(x*2.54,y*2.54,pdata(j).k,64,'linecolor','none')
%setting color range
colormap('jet')
%allowing colorbar to be manipulated
cbar = colorbar('peer', gca);
%setting colorbar label
cbar.Label.String = 'Mach Number';
%setting axii labels
xlabel('r [cm]')
ylabel('r [cm]')
%putting a scatter plot onto the contour
hold on
set(gca,'FontSize', fontsize);
scatter(xxxx2*2.54,yyyy2*2.54,[],'k')
st_fig_range = caxis;
%setting colorbar ranges
caxis([st_fig_range(1) st_fig_range(1)+1]);
cbar.XTick=[round(st_fig_range(1),2):0.1:round(st_fig_range(1),2)+1];
end
%attempting to make axis square
axis square
%saving figure
print(gcf,[figpath,Reynoldsrange,...
sprintf('/ContourM%.0fz%.0f', machnumber,j) ],'-depsc','-loose')
So here is my code, hopefully these comments make sense. This is embedded in some research code I have been working on for several years so it may not be the cleanest, but it generally works really well. I am by no means an expert in Matlab, but I am happy with the codes efficiency (or lack there of). Mostly, the 'axis square' command isnt working.
Due to the colorbar, the axis arent completely square. The plot is slightly taller than it is long. I need to automate this because of how many figures I am producing. Is there a method, brute force or otherwise, that would make this work?
I would love some help! Thanks!
  2 件のコメント
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 10 月 7 日
try
axis equal
Erik Hoberg
Erik Hoberg 2020 年 10 月 7 日
This has the same result as axis square This is just slightly not square, even with the command positioned below all the labels and color bar. Is there a brute force way to define like the number of pixels or something in the figure Frame window?

サインインしてコメントする。

採用された回答

Kiran Felix Robert
Kiran Felix Robert 2020 年 10 月 9 日
Hi Erik,
If axis square and axis equal results are not what you expect, you can manually set the axis sizes in a figure you can use the set function with the axes handle. The following code demonstrates it.
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X) + cos(Y);
contourf(X,Y,Z,10)
cbar = colorbar(gca);
Ax = gca;
set(Ax,'Units','pixels','Position',[10 10 200 200])
You can also refer to this answer regarding the units.
Kiran Felix Robert
  1 件のコメント
Erik Hoberg
Erik Hoberg 2020 年 10 月 13 日
This worked great! Thank you for your help. I was able to drop this command into my code and play with the numbers until the axiis squared up.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by