3 回答

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊
就個(gè)人而言,我覺(jué)得包裝填充功能既優(yōu)雅又方便。要填充兩個(gè)大小相等的行向量Y1
并Y2
共享支持X
(和顏色C):
fill_between_lines = @(X,Y1,Y2,C) fill( [X fliplr(X)], [Y1 fliplr(Y2)], C );

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用函數(shù)FILL完成此操作,以在圖的各部分下創(chuàng)建填充多邊形。您需要按照希望它們?cè)谄聊簧隙询B的順序繪制線條和多邊形,從最底部開始。以下是一些示例數(shù)據(jù)示例:
x = 1:100; %# X range
y1 = rand(1,100)+1.5; %# One set of data ranging from 1.5 to 2.5
y2 = rand(1,100)+0.5; %# Another set of data ranging from 0.5 to 1.5
baseLine = 0.2; %# Baseline value for filling under the curves
index = 30:70; %# Indices of points to fill under
plot(x,y1,'b'); %# Plot the first line
hold on; %# Add to the plot
h1 = fill(x(index([1 1:end end])),... %# Plot the first filled polygon
[baseLine y1(index) baseLine],...
'b','EdgeColor','none');
plot(x,y2,'g'); %# Plot the second line
h2 = fill(x(index([1 1:end end])),... %# Plot the second filled polygon
[baseLine y2(index) baseLine],...
'g','EdgeColor','none');
plot(x(index),baseLine.*ones(size(index)),'r'); %# Plot the red line
這是最終的數(shù)字:
通過(guò)修改axes對(duì)象'Children'屬性中的控制順序,可以在繪制對(duì)象后更改圖形中對(duì)象的堆疊順序。例如,此代碼反轉(zhuǎn)堆疊順序,將綠色多邊形隱藏在藍(lán)色多邊形后面:
kids = get(gca,'Children'); %# Get the child object handles
set(gca,'Children',flipud(kids)); %# Set them to the reverse order
最后,如果您不確切地知道要提前堆疊多邊形的順序(即任何一個(gè)可能是較小的多邊形,您可能想要在頂部),那么您可以調(diào)整'FaceAlpha'屬性以便一個(gè)或兩個(gè)多邊形將顯示部分透明,并在其下方顯示另一個(gè)。例如,以下內(nèi)容將使綠色多邊形部分透明:
set(h2,'FaceAlpha',0.5);
添加回答
舉報(bào)