Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...