Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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 4

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 4

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

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

"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

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
plot David 26 Nov, 2007 18:45:22
image David 26 Nov, 2007 18:45:22
custom David 26 Nov, 2007 18:45:22
axis David 26 Nov, 2007 18:45:22
image plot axis label time frequency David 26 Nov, 2007 18:05:11
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics