Matlab drawing (the best quality article on the whole network)

Drawing Basic Commands

insert image description here

Very detailed

1. Scatter plot

1. The most basic scatter plot

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);

insert image description here

2. Function-specific scatter plot

x = linspace(-2, 2, 100);
y = x .^ 3;  
scatter(x, y);

insert image description here

3. Set the scatter plot of the circle size

x = linspace(-2, 2, 100);
y = x .^ 2;  
sz = linspace(1, 100, 100);
scatter(x, y, sz);

insert image description here

2. Line chart

1. A line

x = 3:2:11;
y=[4,5,9,6,4];  
plot(x, y);

insert image description here

2. Multiple lines

x = 3:2:11;
y=[4,5,9,6,4;5,8,2,4,3];  
plot(x, y);

insert image description here

3. Histogram (three types)

1. The most basic column chart

x = 3:2:11;
y=[4,5,9,6,4];  
bar(x, y);

insert image description here

2. Multivariate histogram

x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];  
bar(x,y);

insert image description here

3. Three-dimensional histogram

Just change bar to bar3.

x=3:5;
y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];  
bar3(x,y);

insert image description here

4. Stacked column chart

y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
bar(y,'stacked');

insert image description here

5. Horizontal column chart

Just change bar to barh:

y=[4,5,9,6,4;5,7,9,8,7;1,3,5,9,7];
barh(y);

insert image description here

4. Match stick figure (very nice)

clc;clear;
x =linspace(0,2*pi,60);
y = sin(x);
stem(x,y);

insert image description here

clc;clear;
x =linspace(0,2*pi,60);
y1 = sin(x);
y2 = cos(x);
stem(x,y1);
hold on
stem(x,y2);

insert image description here

Five, pie chart

1. Basic pie chart

y=[4,5,9,6,4];  
pie(y);

insert image description here

2. Three-dimensional pie chart

Change the pie to pie3

y=[4,5,9,6,4];  
pie3(y);

insert image description here

3. A pie chart that highlights a sector

X=[2,2,1,5,2];
explode = [0 1 0 0 0];
pie(X,explode);

insert image description here

6. Area chart

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);

insert image description here

7. Radar chart

There are detailed explanations in another blog, as follows:
Matalb draws radar charts (four lines of code)
insert image description here
insert image description here

Eight, double coordinate map

Just control the left and right coordinates separately, not too simple. And can be arbitrarily matched with many kinds of graphics.

 x= 1:3;
 y= [9.0725,9.075,9.5175];
 w= [229,230,207];
 yyaxis left%控制左纵轴
 bar(x,y);
 yyaxis right%控制右纵轴
 plot(x,w);

insert image description here

Nine, image segmentation function subplot

subplot function:
How to use: subplot(m,n,p) or subplot(mnp).
subplot is a tool for plotting multiple plots onto a single plane. Among them, m means that the graphs are arranged in m rows, and n means that the graphs are arranged in n columns. The order is first from left to right, then from top to bottom. p means the number of graphs.

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);

insert image description here
Draw another one for easier understanding:

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);

insert image description here

10. Compass chart

clc;clear;
x=-pi:pi/10:pi;
y=sin(x)+cos(x);
compass(x,y,'G')

insert image description here

11. Waterfall diagram

MyWaterFall([6 -3 4 -5 8],["A" "B" "C" "D" "E"]);

The following is the function: don't forget to change the file name.

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

insert image description here

12. Summary

That’s all for now. If there are any other good pictures, please leave a comment to tell the blogger. I will continue to update in the future and try to summarize all the pictures. It's not easy to create, remember to like and follow.

Guess you like

Origin blog.csdn.net/m0_62600503/article/details/125987698