如何更改图像轴标签 [英] How to change image axis labels

查看:103
本文介绍了如何更改图像轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过某些纬度/经度更改图像轴标签,但找不到方法.我尝试了一些基本命令,例如:

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

但是这些表情出现了:

imagesc(data),axis(meshgrid([-180:20:180],[-90:20:90])),彩条 ||的操作数和&&运算符必须可转换为逻辑标量 值.

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}). 

有人可以帮助我吗?仅供参考,我的图像轴标签是数据顺序(从0到N).

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:

推荐答案

从您的问题中推断,您希望将x轴标签设置为-180到180,将y轴标签设置为-90到90.为此,您应该更改轴对象的XTickLabelYTickLabel属性(请注意,您还需要通过相应地修改XTickYTick属性来调整每个轴的刻度数)

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).

因此,假设您的图像存储在矩阵data中,并使用imagesc(data)进行显示,这是将x轴上的刻度标签从-180更改为180的方法:

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)

类似地,以下是将y轴上的刻度标签从-90更改为90的方法:

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(:)))

它应该是这样的:

这篇关于如何更改图像轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆