x = 0.01:0.01:0.08;
y = [3.0743,3.0707,3.0716,3.1133,3.1685,3.1778,3.2467,3.2634];
scatter(x, y);
x = linspace(-2, 2, 100);
y = x .^ 3;
scatter(x, y);
x = linspace(-2, 2, 100);
y = x .^ 2;
sz = linspace(1, 100, 100);
scatter(x, y, sz);
x = 3:2:11;
y=[4,5,9,6,4];
plot(x, y);
x = 3:2:11;
y=[4,5,9,6,4;5,8,2,4,3];
plot(x, y);
x = 3:2:11;
y=[4,5,9,6,4];
bar(x, y);
x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar(x,y);
只需要把bar换成bar3即可。
x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar3(x,y);
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar(y,'stacked');
只需要把bar改成barh即可:
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
barh(y);
clc;clear;
x =linspace(0,2*pi,60);
y = sin(x);
stem(x,y);
clc;clear;
x =linspace(0,2*pi,60);
y1 = sin(x);
y2 = cos(x);
stem(x,y1);
hold on
stem(x,y2);
y=[4,5,9,6,4];
pie(y);
把pie该为pie3即可
y=[4,5,9,6,4];
pie3(y);
X=[2,2,1,5,2];
explode = [0 1 0 0 0];
pie(X,explode);
x=3:8;
y=[45,6,8;7,4,7;6,25,4;7,5,8;9,9,4;2,6,8];
area(x,y);
在另一篇博客上有详解,如下:
Matalb画雷达图(四行代码)
分别控制左右坐标就可以了,不要太简单。而且可以很多种图形任意搭配。
x= 1:3;
y= [9.0725,9.075,9.5175];
w= [229,230,207];
yyaxis left%控制左纵轴
bar(x,y);
yyaxis right%控制右纵轴
plot(x,w);
subplot函数:
使用方法:subplot(m,n,p)或者subplot(m n p)。
subplot是将多个图画到一个平面上的工具。其中,m表示是图排成m行,n表示图排成n列。顺序是先从左到右,再从上到下。p即表示第几个图。
subplot(1,2,1);
y = [3.4308,3.2773,3.1345,3.0526,3.7684,8.1929,15.7455,18.9201];
pie(y);
subplot(1,2,2);
y1=[3.0743,3.0707,3.0716,3.1133,3.1685,3.1778,3.2467,3.2634];
pie(y1);
subplot(2,2,1);
y = [5,9,3,4,7,8,11,6];
plot(y);
subplot(2,2,2);
x=3:8;
y=[45,6,8;7,4,7;6,25,4;7,5,8;9,9,4;2,6,8];
area(x,y);
subplot(2,2,3);
x =linspace(0,2*pi,60);
y1 = sin(x);
y2 = cos(x);
stem(x,y1);
hold on
stem(x,y2);
subplot(2,2,4);
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
barh(y);
clc;clear;
x=-pi:pi/10:pi;
y=sin(x)+cos(x);
compass(x,y,'G')
MyWaterFall([6 -3 4 -5 8],["A" "B" "C" "D" "E"]);
以下是函数:别忘记换文件名了。
function hfig = MyWaterFall(data, Xlabel)
len = length(data);
hfig = figure;
axes1 = axes('Parent',hfig);
hold on;
width = 40;
xbegin = 10;
ybegin = 0;
set(axes1, 'XTick', xbegin+width/2:width*1.5:xbegin+width/2+(len+1)*1.5*width,...
'XTickLabel', [Xlabel "总计"]);
for i = 1:len
if data(i) >= 0
text(xbegin+width/2+(i-1)*1.5*width, sum(data(1:i)), num2str(data(i), '%g'),...
'HorizontalAlignment','center','VerticalAlignment','bottom');
else
text(xbegin+width/2+(i-1)*1.5*width, sum(data(1:i)), num2str(data(i), '%g'),...
'HorizontalAlignment','center','VerticalAlignment','top');
end
end
if sum(data) >= 0
text(xbegin+width/2+(len)*1.5*width, sum(data), num2str(sum(data), '%g'),...
'HorizontalAlignment','center','VerticalAlignment','bottom');
else
text(xbegin+width/2+(len)*1.5*width, sum(data), num2str(sum(data), '%g'),...
'HorizontalAlignment','center','VerticalAlignment','top');
end
for i = 1:len
if data(i) >= 0
rectangle('Position',[xbegin, ybegin, width, data(i)],'facecolor',[0.8500 0.3250 0.0980],...
'LineWidth',0.5);
else
rectangle('Position',[xbegin, ybegin+data(i), width, -data(i)],'facecolor',[0 0.4470 0.7410],...
'LineWidth',0.5);
end
plot([xbegin+width xbegin+1.5*width],[ybegin+data(i) ybegin+data(i)],'k-');
xbegin = xbegin + width * 1.5;
ybegin = ybegin +data(i);
end
if sum(data) >= 0
rectangle('Position',[xbegin, 0, width, ybegin],'facecolor',[0.8500 0.3250 0.0980],...
'LineWidth',0.5);
else
rectangle('Position',[xbegin, ybegin, width, -ybegin],'facecolor',[0.8500 0.3250 0.0980],...
'LineWidth',0.5);
end
end
目前就写这么多吧,还有哪些好图,评论留言告诉博主呀,以后会不断的更新,尽量总结出所有的图。创作不易,记得点赞关注哦。