How to correctly graph a 2D matrix using surface and colour map
이전 댓글 표시
Hello,
I'm using the following code to display a 2D of amino acid concentrations matrix. I wanted the color to reflect how high or low is the number with respect to 0. *********************************
AA_change_fluxes_all =[376.121264363720,41.4792270359525,-4.22520493097745,41.4792270359525,17.4245933564618,41.4792270359525,-51.6998081291888,-57.7544994220980,41.4792270359525,38.6073058842969,-67.2343859737658,41.4792270359525,-100,-100,18.4877035538063,41.4792270359525,-5.40268491509431,36.0377183037992,41.4792270359525,-29.4263181933951;11.9817703299583,864.514962931298,-100,-100,295.060908554746,-100,-100,-100,-100,-100,248.339884632656,-100,-100,-100,-100,-100,-100,-100,-1.19047530094366,-100;-100,-100,2738.49142749238,-100,1268.64583333333,-100,-100,-2.18607278321318,-100,-5.62455508026194,2637.29166666667,-2.33704111793202,-10.8999271409847,-48.6883462257016,7.21170768652618,-100,1066.57137938776,-100,-93.1205572569425,-57.6509700643325;204.571307354865,1693.72013651877,-26.8143500871377,5420.48284379477,1693.72013651877,-100,814.005040147515,352.783514391774,1693.72013651877,930.601178508655,-80.1992956520749,586.173368382117,464.130247777452,83.0206666119299,356.863714792095,-100.000000000000,79.5041644086269,589.892360199511,-95.9839369804205,-75.2775945099139;-100,60.6182185307926,60.6182185307926,60.6182185307926,544.089836054689,60.6182185307926,60.6182185307926,60.6182185307926,-36.7714848837221,-68.2822101748315,38.8424972972340,-58.5463870180832,60.6182185307926,19.3955379255350,-7.30225353741437,-100,60.6182185307926,17.3748520032706,-50.0801521492391,15.6736372744044;Inf,Inf,NaN,Inf,Inf,Inf,NaN,NaN,Inf,Inf,NaN,NaN,NaN,Inf,NaN,Inf,Inf,Inf,Inf,NaN;0,0,0,0,0,0,-312.320444538756,0,0,0,0,0,0,0,0,-99.9999999999999,0,0,0,0;-182.067481795216,-204.562003859698,-56.9687123051353,-204.562003859698,4.56200385969797,-78.9354664860151,-140.285112428740,10.5285957451209,-202.153356461084,-200.644010602912,-203.423615031077,-120.918628655759,-77.7936319280589,-183.939598527674,-64.3243713073015,-172.389079595175,-98.7076121645494,-100,-99.5803580490538,-106.535354669990;-100,-100,3.26888423321124,-100,-100,-100,-99.6547760685308,29.2511256849540,1847.22533215140,-5.62455508026195,-83.5056680043352,-2.33704111793202,17.7366561524045,-48.6883462257016,19.6491142616530,-100,-72.0036855609929,-100,-90.9095182667119,-44.0400774552332;-100,-100,-1.04497581579855,-100,-100,-100,-99.6547760685308,-36.2914485437806,-74.2815597779735,2427.52359306789,-83.5056680043352,-2.33704111793202,-41.9669904070952,-48.6883462257016,-6.28130204082505,-100,-86.2004711404257,-100,-95.5192543183055,-72.4170634024556;-100,353.296477458712,448.122496061392,-100,455.041291827312,181.586874471656,-99.6547760685308,-29.9177093532760,-71.7085514986309,-5.62455508026195,1314.26028944247,131.065159894042,-36.1610623310282,-48.6883462257016,-3.75967830910497,61.2806873977083,-84.8198935587300,-100,-95.0709769096797,-69.6575210810172;1766.15872098268,22.4675390922079,16.7694586067694,-100,-78.9487832232559,-100,706.275319399411,-62.3890821649866,800.027735741498,-5.62455508026195,-92.5775506019559,2088.75049203857,-65.7396894823889,1067.76622039608,-16.6062322449051,382.558661497653,-91.8533237024544,-100,-97.3547513823225,98.6429428277203;519.386012368692,-100,6.05895029091561,-100,-100,-100,-99.6547760685308,71.6419565446931,-30.7100334557142,-5.62455508026194,-83.5056680043352,-2.33704111793200,2098.68266244197,-48.6883462257016,36.4200742755955,-100,-62.8216608490938,-100,-87.9280891182444,-25.6867548133752;-100,-100,-47.8004463543684,-100,-100,-100,-99.8182801837543,-44.2644598109879,-85.7792056306135,-50.3224227939915,-91.3176732372172,-48.5919331648473,-67.9111373422045,655.024175915429,130.030893823160,-100,-92.3696670322040,-100,-97.5224095080883,-84.7482481024817;5336.82758620690,-100,1.93852809542029,-100,1694.03147419579,-100,-99.6547760685308,9.03837772345469,-55.9824084006285,-5.62455508026195,-83.5056680043352,-2.33704111793202,-0.675418357792898,3097.85184983857,5448.47999030838,-100,-76.3818481851688,-100,-92.3311199367154,-52.7912879715689;-100,-100,-1.40793505304670,-100,-100,2735.52541300698,-99.6547760685308,-41.8060647990764,-76.5077495949984,-5.62455508026194,-83.5056680043352,-2.33704111793201,-46.9903313986840,-48.6883462257016,-8.46303348684969,4953.46153846154,-87.3949592338605,-100,-95.9071079487416,-74.8046441440165;-100,-100,-43.9736625079918,-100,-100,-100,-99.8114612444096,-35.0692279271179,-73.7881627826052,-48.4582981610408,-90.9918735485023,-2.33704111793201,-40.8536525717471,-71.9769272404704,-36.8938294778408,-100,898.051769398744,-100,-95.4332931776892,-71.8878968619044;NaN,NaN,Inf,NaN,NaN,NaN,Inf,Inf,Inf,Inf,Inf,NaN,Inf,Inf,Inf,NaN,NaN,Inf,Inf,Inf;1431.13826620254,-100,-72.9140787051765,-100,-100,-100,930.859980604377,-25.2801878865107,-69.8364351830790,-77.9223624867126,-96.1414128099337,-77.1533007711158,-31.9366792361930,-87.9964529629535,-54.4110873318076,-100,-83.8153877293752,-100,1901.74188293378,-67.6496829232867;-100,-100,1.37472789035786,-100,-100.000000000001,-100,-99.6547760685308,0.472286943814896,-59.4404448591095,-5.62455508026194,-83.5056680043352,-2.33704111793203,-8.47839012572184,-48.6883462257016,8.26342674417282,-100,-78.2372979517297,-100,-92.9335896741768,5456.36711296770];
figure(1); xlabels = {'ALA', 'ASP', 'ASN', 'GLN', 'GLU',...
'SER', 'GLY', 'PRO', 'VAL', 'ISL', 'LEU', 'ARG',...
'THE', 'LYS', 'CYS', 'MET', 'PHE', 'TYR', 'TRY',...
'HIS'}; ylabels = {'ALA', 'ASP', 'ASN', 'GLN', 'GLU',...
'SER', 'GLY', 'PRO', 'VAL', 'ISL', 'LEU', 'ARG',...
'THE', 'LYS', 'CYS', 'MET', 'PHE', 'TYR', 'TRY',...
'HIS'}; flat_color_map = surface(AA_change_fluxes_all);
axis([0 20 0 20]); grid on;
colorbar
for k = 1:length(flat_color_map)
zdata = flat_color_map(k).ZData;
flat_color_map(k).CData = zdata;
flat_color_map(k).FaceColor = 'interp';
end
et(gca, 'YTick', 1:20, 'YtickLabel', ylabels)
set(gca, 'XTick', 1:20, 'XtickLabel', xlabels)
************************************************
The problem I'm facing is that there are only 19 colored columns in the figure NOT 20 as I'd expect. The HIS is always missing. Using bar3 seems to solve this problem but I'd really like to use surface/surf as a 2D representation. suggestions?
Thanks Al
답변 (2개)
Walter Roberson
2016년 7월 21일
0 개 추천
surface() calculates the face colors as a weighted version of the vertex colours, so there is always one fewer output face than vertex rows (or columns)
patch() is more flexible about what is used for the coloring.
Also you should consider trying the texturemap options in surface
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!