I created a pcolor image with each grid shaded in based on a value in the matrix C
.
h1 = pcolor(C);
colormap(jet)
h = colorbar;
ylabel(h,'Monthly Correlation (r-value)');
shading flat
Each grid corresponds to a particular year on the x axes and a particular site name on the y axes. How can I add an axes label to show this?
I tried the following but it didn't do anything. Plus, I'd like to put the label in the middle of each grid, not on the edges.
set(h1,'XTick',years')
set(h1,'YTick',a)
x axes labels: years'
looks like this (size 15x1 double)
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
y axes labels: a
looks like this (12x1 cell):
'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'
Current image looks like this:
You are using the wrong handle. For setting labels you need the axes handle and not the pcolor
-handle:
%// get axes handle
ax = gca;
...
%// set labels
set(ax,'XTickLabel',years')
set(ax,'YTickLabel',a)
Example:
%// 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.