画图基本指令
一、散点图
1.最基础的散点图
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);
2.函数专用散点图
x = linspace(-2, 2, 100);
y = x .^ 3;
scatter(x, y);
3.设置圆圈大小的散点图
x = linspace(-2, 2, 100);
y = x .^ 2;
sz = linspace(1, 100, 100);
scatter(x, y, sz);
二、折线图
1.一条线
x = 3:2:11;
y=[4,5,9,6,4];
plot(x, y);
2.多条线
x = 3:2:11;
y=[4,5,9,6,4;5,8,2,4,3];
plot(x, y);
三、柱状图(三种)
1.最基础的柱形图
x = 3:2:11;
y=[4,5,9,6,4];
bar(x, y);
2.多变量柱形图
x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar(x,y);
3.三维的柱形图
只需要把bar换成bar3即可。
x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar3(x,y);
4.堆叠形柱形图
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar(y,'stacked');
5.水平柱形图
只需要把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);
五、饼状图
1.基本饼状图
y=[4,5,9,6,4];
pie(y);
2.三维饼状图
把pie该为pie3即可
y=[4,5,9,6,4];
pie3(y);
3.突出某一扇形的饼状图
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函数:
使用方法: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
文章来源:https://www.toymoban.com/news/detail-783087.html
十二、总结
目前就写这么多吧,还有哪些好图,评论留言告诉博主呀,以后会不断的更新,尽量总结出所有的图。创作不易,记得点赞关注哦。文章来源地址https://www.toymoban.com/news/detail-783087.html
到了这里,关于Matlab 画图(全网最优质文章)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!