2021-01-20 Matlab画图技巧与实例:堆叠图stackedplot
Matlab畫圖技巧與實(shí)例:堆疊圖stackedplot
在MATLAB線圖中,一共有3種類型,分別是
線圖,包括:plot,plot3,stairs,errorbar,area,stackedplot函數(shù)。
對數(shù)圖,包括:loglog,semilogx和semilogx函數(shù),。
函數(shù)圖,包括:fplot,fimplicit和fplot3函數(shù),感覺和ezplot很像,參見
stackedplot函數(shù)專門用來繪制堆疊圖,意思是一組數(shù)據(jù)擁有共同x軸,而y軸數(shù)據(jù)不同。在科研中相對于其他類型圖,雖然不常常出現(xiàn),但偶爾能用到。
注意,注意,注意,stackedplot函數(shù)在2018版本以下是沒有的,只有2018版本及以上才有。
1 堆疊圖stackedplot函數(shù)
1.1 用法
stackedplot(tbl) stackedplot(tbl,vars) stackedplot(___,'XVariable',xvar) stackedplot(X,Y) stackedplot(Y) stackedplot(___,LineSpec) stackedplot(___,Name,Value) stackedplot(parent,___) s = stackedplot(___) clcclear allclose allx = [1:0.1:10];y(:,1) = sin(x);y(:,2) = cos(x);y(:,3) = sin(x).*cos(x);stackedplot(x,y,'ro');可以看出,上圖由三個小圖組成,它們公用x軸,但y軸不同。
1.3 示例2
這里我們可以通過句柄對圖形進(jìn)行更改。
堆疊圖有很多屬性,包括:
例如,可以對x軸和y軸添加名稱。其他屬性類似,直接指定即可。設(shè)定時,注意數(shù)據(jù)類型。
clcclear allclose allx = [1:0.1:10];y(:,1) = sin(x);y(:,2) = cos(x);y(:,3) = sin(x).*cos(x);h = stackedplot(x,y,'r-');h.DisplayLabels = {'y1','y2','y3'};h.XLabel = {'x-axis'};1.4 示例3
在堆疊圖的屬性設(shè)置時,注意,注意,注意,是對整個圖進(jìn)行更改,例如,如果將線型改成虛線,那么三個圖都會被改成虛線。
但是,MATLAB也提供了每個圖的屬性操作,可通過整體屬性中的h.LineProperties進(jìn)行設(shè)置,對于每個小的圖形,h.LineProperties下設(shè)屬性有顏色、線型、線寬、點(diǎn)大小、圖類型等等,如下???????
Color,可以為傳統(tǒng)方法,例如‘r’,'b',可以設(shè)置RGB三色,如[0.5, 0.5, 0.5]MarkerFaceColorMarkerEdgeColorLineStyle,設(shè)置為無時,要用‘none’命令LineWidthMarkerMarkerSizePlotType,這里只能設(shè)置為plot,scatter和stairs函數(shù),不能為其他類型示例如下???????
clcclear allclose allx = [1:0.1:10];y(:,1) = sin(x);y(:,2) = cos(x);y(:,3) = sin(x).*cos(x);h = stackedplot(x,y,'r-');h.DisplayLabels = {'y1','y2','y3'};h.XLabel = {'x-axis'};h.LineProperties(1).Color = 'b';h.LineProperties(1).LineWidth = 1.5;h.LineProperties(2).LineStyle = 'none';h.LineProperties(2).Marker = 'o';h.LineProperties(2).MarkerSize = 8;h.LineProperties(3).PlotType = 'stairs';h.LineProperties(3).Color = 'k';h.LineProperties(3).LineWidth = 1.5;這里,
第一個圖顏色改成藍(lán)色,線寬設(shè)為1.5;
第二個圖線設(shè)置為無,點(diǎn)改為圈,點(diǎn)大小設(shè)為8;
第三個圖線型設(shè)置為階梯圖,顏色設(shè)為黑色,線寬為1.5;
?
總結(jié)
以上是生活随笔為你收集整理的2021-01-20 Matlab画图技巧与实例:堆叠图stackedplot的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021-01-20 Python编程特
- 下一篇: 2021-01-21 linux she