matlab畫二維直方圖以及雙y軸坐標如何修改另一邊y軸的顏色


1.首先講一下如何用hist畫二維直方圖

1 x=[-568179 -766698 -935586 -826865 -393971 -771826 -1529945 -1910695 -1694740 -926367 -306998 -844840 -1828334 -2062815 -2297296 -1498824 -411346 -827922 -1826636 -1844777 -1862918 -1881060 -746534 -100479 -845832 -1832756 -1941081 -2049406 -2157732 -1028398 0 -802745 -1824638 -1686159 -1547681 -1409202 -1270724 -165930 -803741 -1819421 -1710223 -1601026 -1491829 -1382632 -356414 -794668 -1818215 -1734260 -1650305 -1566350 -1482395 -444268 -807800 -1823406 -1748938 -1674470 -1600002 -1525535 -398300 -908544 -1855524 -1808266 -1761009 -1713752 -1666495 -720079 -755299 -1806467 -1742401 -1678336 -1614271 -1550206 -508257 -883998 -1849926 -1821497 -1747566 -1673635 -1599705 -612050 -889367 -1860197 -1946094 -1824594 -1703094 -1581594 -604819 -855354 -1848651 -2070691 -2070691 -1876658 -1557872 -565488 -618422 -1510190 -2195288 -1876658 -2174975 -1348638 -494450 
2  ] 3 [a,b]=hist(x,30); 4 a=a;%/length(x); 5 bar(b,a);

結果是:

可以發現這個畫出來的是標准的直方圖,統計出來的信息是數據落在某個區間中的個數。有時候我們想要得到每個節點所對應的值,橫坐標是節點個數,縱坐標是節點所對應的值。此時我們可以使用plot

1 x=[數據不變] 2 plot_x=1:1:101; 3 plot(plot_x,x,'-b*') 4 xlabel('MRF Node'); 5 ylabel('Initial\_Bconf'); 6 title('Different Initial\_Bconf For Different MRF Nodes');

結果是:

說到這里,我突然發現我想要在這個坐標系中加一個y軸。也就是雙y軸坐標系

在matlab中可以用plotyy

 1 bconf=[-568179 -766698 -935586 -826865 -393971 -771826 -1529945 -1910695 -1694740 -926367 -306998 -844840 -1828334 -2062815 -2297296 -1498824 -411346 -827922 -1826636 -1844777 -1862918 -1881060 -746534 -100479 -845832 -1832756 -1941081 -2049406 -2157732 -1028398 0 -802745 -1824638 -1686159 -1547681 -1409202 -1270724 -165930 -803741 -1819421 -1710223 -1601026 -1491829 -1382632 -356414 -794668 -1818215 -1734260 -1650305 -1566350 -1482395 -444268 -807800 -1823406 -1748938 -1674470 -1600002 -1525535 -398300 -908544 -1855524 -1808266 -1761009 -1713752 -1666495 -720079 -755299 -1806467 -1742401 -1678336 -1614271 -1550206 -508257 -883998 -1849926 -1821497 -1747566 -1673635 -1599705 -612050 -889367 -1860197 -1946094 -1824594 -1703094 -1581594 -604819 -855354 -1848651 -2070691 -2070691 -1876658 -1557872 -565488 -618422 -1510190 -2195288 -1876658 -2174975 -1348638 -494450 
 2  ]  3 msd = [764579.978893 1566061.459336 1397173.470554 1505894.919705 1938788.840738 1560933.670996 802814.336384 422064.792030 638019.347159 1406392.514834 2025761.008413 1487919.901993 504425.214908 0.000000 35463.383173 833934.942435 1921412.940221 1504837.294317 506123.854317 0.000000 0.000000 451698.979188 1586225.592030 2232280.587306 1486927.656531 500003.436458 0.000000 0.000000 175027.053875 1304361.636900 2332759.919705 1530014.724723 508121.677196 0.000000 0.000000 0.000000 1062035.260517 2166829.666716 1529018.752472 513338.064945 0.000000 0.000000 0.000000 950127.380221 1976345.487823 1538091.693432 514544.310111 0.000000 0.000000 0.000000 850364.830701 1888491.347749 1524959.068044 509352.949077 0.000000 0.000000 0.000000 807224.184059 1934458.922214 1424215.026421 477235.717491 0.000000 0.000000 0.000000 666264.597934 1612680.207675 1577460.303911 526292.799705 0.000000 0.000000 0.000000 782553.690775 1824502.611365 1448761.472030 482833.465978 0.000000 0.000000 0.000000 733054.257860 1720709.029668 1443391.983321 472562.824945 0.000000 0.000000 0.000000 751165.883838 1727939.956605 1477405.731661 484108.855055 0.000000 0.000000 0.000000 774887.002362 1767271.818303 1714337.372251 822568.954244 137471.082509 0.000000 157784.000886 984121.237196 1838309.854613 
 4  ]  5  node =1:1:101;  6 % [AX,h1,h2] = plotyy(t,z1,t,z2,'semilogy','plot');  7 [AX,h1,h2] = plotyy(node,bconf,node,msd,'plot','plot');  8 set(h1,'linestyle',':','marker','x','color','b');%曲線的線型  9 %set(h1,'linestyle','-','marker','o','color','g'); 10 set(h2,'linestyle',':','marker','x','color','r'); 11 set(get(AX(1),'Ylabel'),'string','Initial\_Bconf');%x坐標軸名稱 12 set(get(AX(2),'Ylabel'),'string','MSD'); 13 set(get(AX(2), 'Ylabel'),'Color','red'); 14 % set(AX(1),'yTick',[0:10:350]) 15 % set(AX(2),'yTick',[0:10:350]) 16 xlabel('MRF Node'); 17 title('Different Initial\_Bconf For Different MRF Nodes'); 18 set(gca,'ycolor','b');%改變y坐標軸顏色

結果就是:

那此時發現右邊的綠色y軸很不對稱,想調成紅色的,此時可以采用如下方法:


生成的圖片編輯器重點擊view下的小箭頭,選中圖、右鍵選擇show properity editor,然后點擊View下拉菜單中有個plot browser,在右邊看到Axes點擊一下該行,選中它,然后點擊一下右下角的more properties。

此時得到如下界面:

紅色圈圈那里可以修改另一邊的y軸的顏色。當然里面還有很多可以調的,俺的最終結果圖:

 

轉載請注明。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM