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 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