Zoom in on a logarithmic axes

5 次查看(过去 30 天)
Good day everyone,
I aim to have the standard axes response (in linear values) when zooming in on
a logarithmic distributed frequency axes, but, ... with linkaxes functionality
coupling 2 adjacent figures in the y- (Frequency) direction. How can I acheive this?
My tries are shown in the code below.
close all; clear clc;
%% Mathworks question
n_timepnts = 500 ; % Number of time points
n_freqs = 100 ; % Number of frequency points
Freq = logspace(0,3,n_freqs) ; % Logarithmic distribution
DataArray = rand(n_freqs,n_timepnts) ; % Some arbitrary data array
Spectrum = rand(n_freqs,1).*max(DataArray,[],2) ; % Arbitrary spectrum
time = linspace(0,365,n_timepnts); % Arbitrary time array in days
%% imagesc approach
figure(1);clf
set(1,'Position',[ 28 250 1187 420],'Name','');
ax(1) = subplot(1,9,1:2);
plot(Spectrum,log10(Freq))
xlabel('Spectral max.')
ylabel(' Frequency [Hz]')
title('Arbitrary Spectrum')
grid on;
%---
ax(2) = subplot(1,9,4:9);
imagesc(time,log10(Freq),DataArray)
set(gca,'YDir','normal');
xlabel('Day of Year')
ylabel(' Frequency [Hz]')
title('Spectral data over time')
%---
linkaxes(ax,'y')
Using the contourf approach (not preferred due to slow response)
%% contourf approach
figure(2);clf
set(2,'Position',[ 48 250 1187 420],'Name','');
ax(1) = subplot(1,9,1:2);
semilogy(Spectrum,Freq)
xlabel('Spectral max.')
ylabel(' Frequency [Hz]')
title('Arbitrary Spectrum')
grid on;
%---
[X,Y] = meshgrid(time,log10(Freq));
ax(2) = subplot(1,9,4:9);
contourf(X,Y,DataArray,'LineColor','none')
% contourf(time,Freq,DataArray,'LineColor','none')
set(gca,'YDir','normal');
xlabel('Day of Year')
ylabel(' Frequency [Hz]')
title('Spectral data over time')
%---
% linkaxes(ax,'y')
yields.
Help please!
Kind regards,
Eric

采纳的回答

Kevin Holly
Kevin Holly 2022-11-5
You can add Listeners as shown below.
%% Parameters
n_timepnts = 500 ; % Number of time points
n_freqs = 100 ; % Number of frequency points
Freq = logspace(0,3,n_freqs) ; % Logarithmic distribution
DataArray = rand(n_freqs,n_timepnts) ; % Some arbitrary data array
Spectrum = rand(n_freqs,1).*max(DataArray,[],2) ; % Arbitrary spectrum
time = linspace(0,365,n_timepnts); % Arbitrary time array in days
%% contourf approach
figure(2);clf
set(2,'Position',[ 48 250 1187 420],'Name','');
ax(1) = subplot(1,9,1:2);
semilogy(Spectrum,Freq)
xlabel('Spectral max.')
ylabel(' Frequency [Hz]')
title('Arbitrary Spectrum')
grid on;
%---
[X,Y] = meshgrid(time,log10(Freq));
ax(2) = subplot(1,9,4:9);
contourf(X,Y,DataArray,'LineColor','none')
% contourf(time,Freq,DataArray,'LineColor','none')
set(gca,'YDir','normal');
xlabel('Day of Year')
ylabel(' Frequency [Hz]')
title('Spectral data over time')
%---
% Add Listeners
addlistener(ax(1),'YLim', 'PostSet',@(~,events)set(ax(2),'YLim',log10(ax(1).YLim)))
addlistener(ax(2),'YLim', 'PostSet',@(~,events)set(ax(1),'YLim',10.^(ax(2).YLim)))
  1 个评论
Eric Kappel
Eric Kappel 2022-11-5
I certainly would not have come up with such an elegant solution!!! I think I can exploit this feature a lot more!
Thank you!!!
Kind regards,
Eric

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by