Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change image axis labels

I'm trying to change the image axis labels with some latitude/longitude but I can't find how to do it. I tried some basic commands like:

imagesc(data)
axis(meshgrid([-180:20:180],[-90:20:90]))
colorbar

but these expression appeared:

imagesc(data),axis(meshgrid([-180:20:180],[-90:20:90])), colorbar Operands to the || and && operators must be convertible to logical scalar values.

Error in axis>allAxes (line 448)
result = all(ishghandle(h)) && ...

Error in axis (line 57)
if ~isempty(varargin) && allAxes(varargin{1}). 

Can anybody help me? FYI, my image axis labels are the data order (from 0 to N).

My desired results is an image looks like a world map, with graticule/grid lines as the axes. It should be looked like this:

enter image description here

like image 859
Prayudha Hartanto Avatar asked Feb 25 '13 16:02

Prayudha Hartanto


2 Answers

From your question I infer that you want to set the x-axis labels from -180 to 180, and the y-axis labels from -90 to 90. To do this, you should change the XTickLabel and YTickLabel properties of the axis object (note that you'll also need to adjust the number of ticks in each axis by modifying the XTick and YTick properties accordingly).

So, assuming that your image is stored in the matrix data and you display it with imagesc(data), here's how to change the tick labels in the x-axis to be from -180 to 180:

xticklabels = -180:20:180;
xticks = linspace(1, size(data, 2), numel(xticklabels));
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)

Similarly, here's how to change the tick labels in the y-axis to be from -90 to 90:

yticklabels = -90:20:90;
yticks = linspace(1, size(data, 1), numel(yticklabels));
set(gca, 'YTick', yticks, 'YTickLabel', flipud(yticklabels(:)))

This is what it should look like:

enter image description here

like image 151
Eitan T Avatar answered Oct 06 '22 00:10

Eitan T


Can't say I fully understand what you mean, so here goes. To add a label to an axis use xlabel and ylabel, for example:

xlabel('time [sec]'); ylabel('Amplitude');

To change the labels of the axis ticks, use something like:

plot(1:4)
set(gca,'Xtick',1:4,'XTickLabel',{'a', 'b', 'c', 'd'})

Working with imagesc you may want to add this line:

set(gca, 'YDir', 'reverse');

this will set the numbers on the Ticks growing for the bottom left corner...

like image 20
bla Avatar answered Oct 06 '22 01:10

bla