Zoom in on a logarithmic axes

5 ビュー (過去 30 日間)
Eric Kappel
Eric Kappel 2022 年 11 月 5 日
コメント済み: Eric Kappel 2022 年 11 月 5 日
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 Center および File ExchangeVisual Exploration についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by