将轴标签添加到pcolor图像

时间:2015-03-20 03:22:38

标签: image matlab axes

我创建了一个pcolor图像,每个网格都根据矩阵C中的值进行着色。

h1 = pcolor(C);
colormap(jet)
h = colorbar;
ylabel(h,'Monthly Correlation (r-value)');
shading flat

每个网格对应于x轴上的特定年份和y轴上的特定站点名称。如何添加轴标签以显示此信息?

我尝试了以下但它没有做任何事情。另外,我想将标签放在每个网格的中间,而不是边缘。

set(h1,'XTick',years')
set(h1,'YTick',a)

x轴标签:years'看起来像这样(尺寸15x1加倍)

    1999
    2000
    2001
    2002
    2003
    2004
    2005
    2006
    2007
    2008
    2009
    2010
    2011
    2012
    2013

y轴标签:a看起来像这样(12x1单元格):

'09-003-1003-88101'
'09-009-0027-88101'
'25-013-0008-88101'
'25-025-0042-88101'
'33-005-0007-88101'
'33-009-0010-88101'
'33-011-5001-88101'
'33-015-0014-88101'
'33-015-0018-88101'
'44-003-0002-88101'
'44-007-1010-88101'
'44-009-0007-88101'

当前图片如下所示: enter image description here

1 个答案:

答案 0 :(得分:1)

您使用的是错误的句柄。要设置标签,您需要轴处理,而不是pcolor - 句柄:

%// get axes handle
ax = gca;
...
%// set labels
set(ax,'XTickLabel',years')
set(ax,'YTickLabel',a)

示例:

%// example data
C =  [...
0.06    -0.22   -0.10   0.68    NaN     -0.33;
0.04    -0.07   0.12    0.23    NaN     -0.47;
NaN     NaN     NaN     NaN     NaN     0.28;
0.37    0.36    0.14    0.58    -0.14   -0.15;
NaN     0.11    0.24    0.71    -0.13   NaN;
0.57    0.53    0.41    0.65    -0.43   0.03 ];

%// original plot
h1 = pcolor(C);
colormap(jet)
h = colorbar;
ylabel(h,'Monthly Correlation (r-value)');
shading flat

%// get axes handle
ax = gca;

%// labels (shortened to fit data)
years = [1999, 2000, 2001, 2002, 2003, 2004];
a = {'09-003-1003-88101', '09-009-0027-88101', '25-013-0008-88101',  ...
     '25-025-0042-88101', '33-005-0007-88101', '33-009-0010-88101'};

%// adjust position of ticks
set(ax,'XTick', (1:size(C,2))+0.5 )
set(ax,'YTick', (1:size(C,1))+0.5 )
%// set labels
set(ax,'XTickLabel',years')
set(ax,'YTickLabel',a)

enter image description here