Thread Subject:
how to display IMAGE with custom X, Y axis ticks ?

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: David

Date: 26 Nov, 2007 23:04:15

Message: 1 of 7

Hi,

I want to display a Frequency vs Time plot.
The data are stored as an image in an array
and I can display using "imagesc",
but the X and Y labels are in 1000x1000 "pixel" units.

I want to relabel the X axis to represent time,
going from 0 to 10 seconds.

I want to relabel the Y axis to represent frequency,
which goes from 10 Hz to 1000 Hz, on a log scale.

I have looked at the "image()" function and its various
options, but I can't figure out how to do it.

Does anyone out there know how to put custom axis labels on
your image data?

Any help appreciated,
David Jones
djones.nospam@remove.mcmaster.ca

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: Bruno Luong

Date: 26 Nov, 2007 23:25:36

Message: 2 of 7

"David " <djones.nospam@remove.mcmaster.ca> wrote in message
<fifjdf$5s6$1@fred.mathworks.com>...

x=linspace(0,10,1000); % 0 to 10 s, 1000 samples
y=logspace(1,3,1000); % 10^1 to 10^3, 1000 samples
imagesc(x,y,data);
set(gca,'Yscale','log','Ydir','normal');

Bruno

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: David

Date: 26 Nov, 2007 23:44:32

Message: 3 of 7

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fifklg$p53$1@fred.mathworks.com>...
> "David " <djones.nospam@remove.mcmaster.ca> wrote in message
> <fifjdf$5s6$1@fred.mathworks.com>...
>
> x=linspace(0,10,1000); % 0 to 10 s, 1000 samples
> y=logspace(1,3,1000); % 10^1 to 10^3, 1000 samples
> imagesc(x,y,data);
> set(gca,'Yscale','log','Ydir','normal');
>
> Bruno
>

Thanks, ... that *ALMOST* solves my problem,
but there is an error when I try this.

The Y axis labels are not positioned properly.
There seems to be a problem with the "YLim" axis property.
Presumably it is still linear, while the labels are log.

Any suggestions?
I don't know how to update "YLim" appropriately.


You can see for yourself:

N = 32;
data = rand(N,N);
x=linspace(0,10,N); % 0 to 10 s, 64 samples
A = log10(5);
B = log10(60);
y=logspace(A,B,N); % 10^A to 10^B, 64 samples
imagesc(x,y,data);
set(gca,'Yscale','log','Ydir','normal', 'YTick', [5 10 20 30
40 50 60]);
xlabel('Time (sec)'); ylabel('Frequency (Hz)');

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: Bruno Luong

Date: 27 Nov, 2007 12:35:36

Message: 4 of 7

"David " <djones.nospam@remove.mcmaster.ca> wrote in message
>
> The Y axis labels are not positioned properly.
> There seems to be a problem with the "YLim" axis property.
> Presumably it is still linear, while the labels are log.

You probably should define tick and label manually like this:

%%%%%%%%%%%%%%%%%

N = 16;
data = rand(N,N);
x=linspace(0,10,N); % 0 to 10 s, 16 samples

Ymin=5; Ymax=60; % Min and max of Y-axis
Ytick=[5 10 20 30 40 50 60];
logy=linspace(log(Ymin),log(Ymax),N);

imagesc(x,logy,data, ...
    'Ydir','normal', ...
    'YTick', log(Ytick), ...
    'YTickLabel', ...
    arrayfun(@num2str, Ytick(:), 'UniformOutput', false));

xlabel('Time (sec)');
ylabel('Frequency (Hz)');

Bruno

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: Salman

Date: 20 Apr, 2012 01:29:13

Message: 5 of 7

Thank you so much Bruno,

Seriously, your response was of much help. The author of this thread did not have enough courtesy to take a moment and thank you after his job got done. But I couldn't rest in peace without expressing my gratitude.

Salman

"Bruno Luong" <b.luong@fogale.fr> wrote in message <fih2uo$4vg$1@fred.mathworks.com>...
> "David " <djones.nospam@remove.mcmaster.ca> wrote in message
> >
> > The Y axis labels are not positioned properly.
> > There seems to be a problem with the "YLim" axis property.
> > Presumably it is still linear, while the labels are log.
>
> You probably should define tick and label manually like this:
>
> %%%%%%%%%%%%%%%%%
>
> N = 16;
> data = rand(N,N);
> x=linspace(0,10,N); % 0 to 10 s, 16 samples
>
> Ymin=5; Ymax=60; % Min and max of Y-axis
> Ytick=[5 10 20 30 40 50 60];
> logy=linspace(log(Ymin),log(Ymax),N);
>
> imagesc(x,logy,data, ...
> 'Ydir','normal', ...
> 'YTick', log(Ytick), ...
> 'YTickLabel', ...
> arrayfun(@num2str, Ytick(:), 'UniformOutput', false));
>
> xlabel('Time (sec)');
> ylabel('Frequency (Hz)');
>
> Bruno

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: Salman

Date: 20 Apr, 2012 22:49:15

Message: 6 of 7

Hey Bruno, I guessed yesterday that my problem was solved but apparently there is still a trouble with the way Matlab scales the Yaxis with the log command.
My original yscale values are spaced linearly between 0.3 and 50, using linspace:
f=linspace(.3,50,100);
And when I use, set(gca,'Yscale','log'), it adjusts the y-axis limits to go from 10^-1.3 = .05 to 10^1.69=50. This totally changes the y-axis value corresponding to each pixel in the image.
Because I want the y-axis to retain its both bounds, i.e. it should go from 10^-.522=.3, to 10^1.69=50. And just change the spacing between these bounds from linear to logarithmic.

So far, I haven't been able to instruct the Matlab to set tight bounds in logarithmic scale i.e. retain the bounds from when the axis was in the linear scale to now when the logarithmic scaling is applied.

Please help me here, because this trivial problem is now getting me irritated.
"Bruno Luong" <b.luong@fogale.fr> wrote in message <fih2uo$4vg$1@fred.mathworks.com>...
> "David " <djones.nospam@remove.mcmaster.ca> wrote in message
> >
> > The Y axis labels are not positioned properly.
> > There seems to be a problem with the "YLim" axis property.
> > Presumably it is still linear, while the labels are log.
>
> You probably should define tick and label manually like this:
>
> %%%%%%%%%%%%%%%%%
>
> N = 16;
> data = rand(N,N);
> x=linspace(0,10,N); % 0 to 10 s, 16 samples
>
> Ymin=5; Ymax=60; % Min and max of Y-axis
> Ytick=[5 10 20 30 40 50 60];
> logy=linspace(log(Ymin),log(Ymax),N);
>
> imagesc(x,logy,data, ...
> 'Ydir','normal', ...
> 'YTick', log(Ytick), ...
> 'YTickLabel', ...
> arrayfun(@num2str, Ytick(:), 'UniformOutput', false));
>
> xlabel('Time (sec)');
> ylabel('Frequency (Hz)');
>
> Bruno

Subject: how to display IMAGE with custom X, Y axis ticks ?

From: Bruno Luong

Date: 21 Apr, 2012 07:07:13

Message: 7 of 7

"Salman" wrote in message <jmsp5b$89k$1@newscl01ah.mathworks.com>...
> Hey Bruno, I guessed yesterday that my problem was solved but apparently there is still a trouble with the way Matlab scales the Yaxis with the log command.
> My original yscale values are spaced linearly between 0.3 and 50, using linspace:
> f=linspace(.3,50,100);
> And when I use, set(gca,'Yscale','log'), it adjusts the y-axis limits to go from 10^-1.3 = .05 to 10^1.69=50. This totally changes the y-axis value corresponding to each pixel in the image.
> Because I want the y-axis to retain its both bounds, i.e. it should go from 10^-.522=.3, to 10^1.69=50. And just change the spacing between these bounds from linear to logarithmic.
>
> So far, I haven't been able to instruct the Matlab to set tight bounds in logarithmic scale i.e. retain the bounds from when the axis was in the linear scale to now when the logarithmic scaling is applied.
>
> Please help me here, because this trivial problem is now getting me irritated.

MATLAB can't plot an image in logscale. That's why in my code I have to set manually Y axis in log, and retains the 'linear' property for 'YDir'.

N = 16;
data = rand(N,N);
x=linspace(0,10,N); % 0 to 10 s, 16 samples

Ymin=0.3; Ymax=50; % Min and max of Y-axis
Ytick=[0.3 1 3 10 20 30 50];
logy=linspace(log(Ymin),log(Ymax),N);

imagesc(x,logy,data);
set(gca, ...
    'Ydir','normal', ...
    'YTick', log(Ytick), ...
    'YTickLabel', ...
    arrayfun(@num2str, Ytick(:), 'UniformOutput', false));

xlabel('Time (sec)');
ylabel('Frequency (Hz)');

% Bruno

Bruno

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matlab Salman 20 Apr, 2012 18:49:19
yscale Salman 20 Apr, 2012 18:49:19
yaxis Salman 20 Apr, 2012 18:49:19
log scale Salman 20 Apr, 2012 18:49:19
ticks Salman 19 Apr, 2012 21:29:14
log Salman 19 Apr, 2012 21:29:14
imagesc Salman 19 Apr, 2012 21:29:14
scale Salman 19 Apr, 2012 21:29:14
plot David 26 Nov, 2007 18:45:22
custom David 26 Nov, 2007 18:45:22
image David 26 Nov, 2007 18:45:22
axis David 26 Nov, 2007 18:45:22
image plot axis la... David 26 Nov, 2007 18:05:11
rssFeed for this Thread

Contact us