Zoom in on a logarithmic axes

4 Ansichten (letzte 30 Tage)
Eric Kappel
Eric Kappel am 5 Nov. 2022
Kommentiert: Eric Kappel am 5 Nov. 2022
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

Akzeptierte Antwort

Kevin Holly
Kevin Holly am 5 Nov. 2022
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 Kommentar
Eric Kappel
Eric Kappel am 5 Nov. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by