Both Pcolor color plot and quiver plot in log scale

13 次查看(过去 30 天)
Hai,
I need to plot pcolor plot with y-axis in log scale and over plot with quiver plot in log scale.
Please help me how to do this.
Here is my code:
pcolor(1:365,pr(:,1),Ez1.*10^6);shading interp; colormap('jet(25)');colorbar;set(gca,'YScale','log');
hold on ; quiverInLogScale(1:15:365,MP,Zu1(:,1:15:365),Zv1(:,1:15:365))%,2,'-k')
set(gca,'Ydir','reverse');
caxis([0 8]);
ylim([1 100]);%xlim([0 396]);
title('(a) Daily mean (2005:2021) H2O (ppmv)')
set(gca, 'XTick', [1 31 59 90 120 151 181 212 243 273 304 335 365]);
set(gca,'XTickLabel', {'1' '31' '59' '90' '120' '151' '181' '212' '243' '273' '304' '335' '365'})
ylabel('P (hPa)')
set(gca, 'YTick', [1 10 21.54 31.62 56.23 100]);
set(gca,'YTickLabel', {'1', '10','21.54','31.62','56.23','100'})
colormap(ax1,jet(20)), colorbar

回答(1 个)

Abhinaya Kennedy
Abhinaya Kennedy 2024-8-1
To plot a pcolor plot with a logarithmic y-axis and overlay it with a quiver plot also in a logarithmic scale, you need to ensure that both plots are consistent with the log scale.
% Data setup (assuming pr, Ez1, MP, Zu1, and Zv1 are already defined)
% pr should be a column vector representing the y-axis values
% Ez1 should be a matrix for the pcolor plot
% MP should be a column vector representing the y-axis values for the quiver plot
% Zu1 and Zv1 should be matrices for the quiver plot
% Create the pcolor plot
figure;
pcolor(1:365, pr(:, 1), Ez1 .* 10^6);
shading interp;
colormap('jet(25)');
colorbar;
set(gca, 'YScale', 'log');
hold on;
% Adjust MP to log scale for the quiver plot
logMP = log10(MP);
logMP = logMP - min(logMP); % Normalize to avoid negative values
logMP = logMP / max(logMP); % Scale to [0, 1]
logMP = 10 .^ (logMP * (log10(max(pr)) - log10(min(pr))) + log10(min(pr))); % Scale back to original range
% Create the quiver plot
quiver(1:15:365, logMP, Zu1(:, 1:15:365), Zv1(:, 1:15:365), 2, '-k');
% Set properties
set(gca, 'Ydir', 'reverse');
caxis([0 8]);
ylim([1 100]);
title('(a) Daily mean (2005:2021) H2O (ppmv)');
set(gca, 'XTick', [1 31 59 90 120 151 181 212 243 273 304 335 365]);
set(gca, 'XTickLabel', {'1', '31', '59', '90', '120', '151', '181', '212', '243', '273', '304', '335', '365'});
ylabel('P (hPa)');
set(gca, 'YTick', [1 10 21.54 31.62 56.23 100]);
set(gca, 'YTickLabel', {'1', '10', '21.54', '31.62', '56.23', '100'});
% Adjust colormap and colorbar
colormap('jet(20)');
colorbar;
  1. Logarithmic Scaling of MP: The MP array is transformed to a logarithmic scale to match the y-axis of the plot.
  2. Normalization and Scaling: The logMP variable is normalized and scaled back to the original range to ensure proper placement on the logarithmic y-axis.
This should give you a pcolor plot (https://www.mathworks.com/help/matlab/ref/pcolor.html) with a logarithmic y-axis and an overlaid quiver plot (https://www.mathworks.com/help/matlab/ref/quiver.html) that is consistent with the logarithmic scale.

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by