41 views (last 30 days)
Show older comments
Wiqas Ahmad on 22 Apr 2024 at 5:54
-
-
Link
Direct link to this question
https://www.mathworks.com/matlabcentral/answers/2109966-the-last-x-axis-tick-is-missing-invisible-in-fig-2-and-3
Commented: Wiqas Ahmad about 4 hours ago
Open in MATLAB Online
Greetings! I have plotted four figures. Figures 2 and 4 are right but Figures 2 and 3 don't display the last tick at x-axis as shown in picture below.I have tried several other statements but the problem persist. The code is:
clear, clc, close all
a_ref = 0.05;
Reff_ref = 20;
z_bottom = 1000:1000:4000;
Height = linspace(0, 200, 1000); % Increased resolution for smoother lines
FOV = [0.2, 0.5, 1, 2, 5, 10];
cloud = 'hom*o';
for h = 1:length(z_bottom)
main_fig = figure('NumberTitle', 'off', 'Name', ['Height ', num2str(z_bottom(h)), 'm']);
Area = []; % for sort
COLOR = {'r', 'g', 'b', [0.8500 0.3250 0.0980], [0.4660 0.6740 0.1880], [0 0.4470 0.7410]};
ylim_max = 0;
for a = 0.01:0.01:a_ref
for r = 4:Reff_ref
clf(main_fig); % Clear the current figure
subplot(1, 1, 1); % Create subplot for all FOVs
hold on;
for f = 1:length(FOV)
Height = genHeight(z_bottom(h))';
load(['MCdatabase_', cloud, '/', num2str(a), '-', num2str(r), 'um/', num2str(z_bottom(h)), 'm-', num2str(FOV(f)), 'mrad/I0.mat']);
load(['MCdatabase_', cloud, '/', num2str(a), '-', num2str(r), 'um/', num2str(z_bottom(h)), 'm-', num2str(FOV(f)), 'mrad/Q0.mat']);
I_para = 1/2 * (I0 + Q0);
I_per = 1/2 * (I0 - Q0);
% Plotting all FOV plots on a single figure for each cloud height
plot(Height, sum(I_para, 2) .* Height.^2, 'Color', COLOR{f}, 'LineWidth', 1.5)
hold on
plot(Height, sum(I_per, 2) .* Height.^2, 'Color', COLOR{f}, 'LineStyle', '--', 'LineWidth', 1.5)
title(['Height ', num2str(z_bottom(h)), 'm'])
% Add annotation for polarized signals
if f == 1
annotation('textbox', [0.15, 0.16, 0.1, 0.1], 'String', 'P_{\perp}', 'Color', 'k', 'EdgeColor', 'none', 'FontWeight', 'bold', 'FontSize', 12);
annotation('textbox', [0.22, 0.5, 0.1, 0.1], 'String', 'P_{\mid\mid}', 'Color', 'k', 'LineStyle', '--', 'EdgeColor', 'none', 'FontWeight', 'bold', 'FontSize', 12);
end
Area = [Area, [z_bottom(h); FOV(f); pi * ((2.5 * cot(FOV(f) * 1e-3/2) + z_bottom(h)) * tan(FOV(f) * 1e-3/2))^2]];
% Calculate the maximum y-axis limit
ylim_max = max(ylim_max, max(sum(I_para, 2) .* Height.^2));
ylim_max = max(ylim_max, max(sum(I_per, 2) .* Height.^2));
end
hold off;
end
end
% Figure settings based on the data
zoom on
xlabel('Height of the cloud (m)','FontSize',14,'FontWeight','normal');
ylabel('Backscattering signal (Unit)','FontSize',14,'FontWeight','normal');
set(gca,'color','w','Fontsize',12,'LineWidth',1.5,'Fontweight','normal');
set(gca,'box','off','Fontname','Arial','Fontsmoothing','on');
% Set x-axis limits and ticks with a difference of 50 for all figures
xlim_min = z_bottom(h);
xlim_max = max(Height);
% Adjust xticks for last tick visibility
if h == 1
xticks = 1000:50:1150;
elseif h == 2
xticks = [2000 2050 2100 2150]; % Corrected x-ticks for Figure 2
elseif h == 3
xticks = [3000 3050 3100 3150]; % Corrected x-ticks for Figure 3
else
xticks = 4000:50:xlim_max;
end
set(gca,'xlim',[xlim_min, xlim_max],'xtick',xticks,'ylim',[0 ylim_max],'ytick',[0:0.1:ylim_max]);
set(gca,'xgrid','on','ygrid','on','gridcolor','k');
% Create legend entries for each FOV value
legend_labels = cell(1, length(FOV) * 2); % Preallocate space for legend labels
for i = 1:length(FOV)
legend_labels{(i-1)*2+1} = [num2str(FOV(i)), 'mrad'];
legend_labels{(i-1)*2+2} = [num2str(FOV(i)), 'mrad'];
end
% Plot the legend entries in two rows
legend(legend_labels, 'Location', 'NorthEast', 'NumColumns', 3);
legend boxoff
end
I replaced the section but got the ticks with different values than desirable. The values should be 2150 and 3150 rather than mentionned.
% Adjust xticks for last tick visibility
if h == 1
xticks = 1000:50:1150;
elseif h == 2
xticks = [2000:50:2100, max(Height)]; % Corrected x-ticks for Figure 2
elseif h == 3
xticks = [3000:50:3100, max(Height)]; % Corrected x-ticks for Figure 3
else
xticks = 4000:50:xlim_max;
end
Please if anybody can solve it.
4 Comments Show 2 older commentsHide 2 older comments
Show 2 older commentsHide 2 older comments
Aquatris on 22 Apr 2024 at 8:32
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2109966-the-last-x-axis-tick-is-missing-invisible-in-fig-2-and-3#comment_3139426
when you plot a figure, by default Matlab sets x-limits to be from minimum of x vector to maximum of xvector. So in your case you have your x vector maximum at 3146.25. So when you want to put an x-tick at 3150, it is not visible cause it is outside of the bounds. So you should change your xlim() instead of xticks to have 3150 or 2150 in your plot
Wiqas Ahmad about 5 hours ago
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2109966-the-last-x-axis-tick-is-missing-invisible-in-fig-2-and-3#comment_3141641
The xlimits are set by the program by default from the data. The range is 150 in each case. The same xlimits work for figure 1 and 4 but not for figure 2 and 3. Can you be more specific please and tell me how can we make changes to the code?
Walter Roberson about 5 hours ago
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2109966-the-last-x-axis-tick-is-missing-invisible-in-fig-2-and-3#comment_3141676
Height = genHeight(z_bottom(h))';
We need the code for genHeight
Wiqas Ahmad about 4 hours ago
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2109966-the-last-x-axis-tick-is-missing-invisible-in-fig-2-and-3#comment_3141716
Actually we modeled four types of clouds. From bottom to top, each cloud Height is 150m. z_bottom referes to the cloud bottom with heights 1000,2000,3000 and 4000m (xlim_min) . The cloud top is at maximum height of 1150,2150,3150 and 4150m (xlim_max) in each case.
Sign in to comment.
Sign in to answer this question.
Answers (0)
Sign in to answer this question.
See Also
Tags
- missing_tick
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office