将轴标签添加到 pcolor 图像
Add axes label to pcolor image
我创建了一个 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'
当前图像如下所示:
您使用的句柄有误。要设置标签,您需要坐标轴句柄而不是 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)
我创建了一个 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'
当前图像如下所示:
您使用的句柄有误。要设置标签,您需要坐标轴句柄而不是 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)