数学建模常用的Matlab绘图总结

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

饼状图
Expenses = [20 10 40 12 20 19 5 15];
ExpenseCategories = {'Food','Medical','Lodging','Incidentals',...
'Transport','Utilities','Gifts','Shopping'};
MostLeastExpensive = (Expenses==max(Expenses)|Expenses==min(Expenses)); h=pie(gca,Expenses,MostLeastExpensive,ExpenseCategories);
Shopping
Incidentals
Expenses = [20 10 40 12 20 19 5 15];
MostLeastExpensive = (Expenses==max(Expenses)|Expenses==min(Expenses)); h=pie(gca,Expenses,MostLeastExpensive);
legend('Food','Medical','Lodging','Incidentals',...
'Transport','Utilities','Gifts','Shopping');
9%
Expenses = [20 10 40 12 20 19 5 15]; MostLeastExpensive = [0 1 0 1 0 1 0 1];%分割 h=pie(gca,Expenses,MostLeastExpensive); legend('Food','Medical','Lodging','Incidentals',... 'Transport','Utilities','Gifts','Shopping');
x = [20 10 40 12 20 19 5 15]; explode = [4 2 2 2 2 4 2 2];
label = {'Food','Medical','Lodging','Incidentals',... 'Transport','Utilities','Gifts','Shopping',}'; figure('color','w','renderer','openGL'); h = pie3(x,explode);
h = findobj(h,'Type','text');
set(h,{'string'},cellfun(@strcat,get(h,{'string'}),label,'un',0),'FontName','Times New Roman','FontSize',16);
%set(h,{'string'},strcat(get(h,{'string'}),label));
%cm = [72 65 137;143 184 58;193 60 49;41 121 201;... % 60 65 150;189 84 58;193 160 90;241 121 101]/255; colormap(jet), shading interp view(18,20), camproj perspective light('Position',[1 2 3],'Style','inf') lighting gouraud
7%
9%
11%
x = [20 10 40 12 20 19 5 15];
explode = [4 2 2 2 2 4 2 2];
label = {'14% Food','7% Medical','28% Lodging','9% Incidentals',...
'14% Transport','13% Utilities','4% Gifts','11% Shopping',}'; figure('color','w','renderer','openGL');
pie3s(x,'Explode',explode,'Labels',label)%见Matlab_pie3s
直方图
Y = round(rand(5,3)*10); figure;
subplot(2,2,1); bar(Y,'grouped'); title('Group') subplot(2,2,2); bar(Y,'stacked'); title('Stack') subplot(2,2,3); bar(Y,'histc'); title('Histc') subplot(2,2,4); bar(Y,'hist'); title('Hist')
stream = RandStream('mrg32k3a','Seed',4); y1 = rand(stream,10,5);
hb = bar(y1,'stacked'); colormap(summer); hold on y2 = rand(stream,10,1);
set(gca,'FontSize',14,'FontName','Times New Roman') hp = plot(1:10,y2,'marker','square','markersize',12,...
'markeredgecolor','y','markerfacecolor',[.6,0,.6],... 'linestyle','-','color','r','linewidth',2); hold off legend([hb,hp],'Carrots','Peas','Peppers','Green Beans',...
'Cucumbers','Eggplant','Location','SouthEastOutside')
1
2
34
5
5
10Group
1
2
34
5
10
20
30Stack
123450
5
10Histc
12345
5
10Hist
Data = [1,-2,3,1,-1,-2 4 2 3]; DataP = Data; DataN = Data;
DataP(Data < 0) = 0; DataN(Data > 0) = 0; figure;
bar(DataP,0.5,'k','EdgeColor','k'); hold on ;
bar(DataN,0.5,'b','EdgeColor','b');
Y = round(rand(5,3)*10); figure;
subplot(2,2,1); bar3(Y,'grouped');
title('Group','FontSize',14,'FontName','Times New Roman') subplot(2,2,2); bar3(Y,'stacked');
title('Stack','FontSize',14,'FontName','Times New Roman') subplot(2,2,3); bar3(Y,'histc');
title('Histc','FontSize',14,'FontName','Times New Roman') subplot(2,2,4); bar3(Y,'hist');
title('Hist','FontSize',14,'FontName','Times New Roman')
Group
10
20
Stack
Histc
Hist
杆状图Data = [1,-2,3,1,-1,-2 4 2 3];
DataP = Data;
DataN = Data;
DataP(Data < 0) = NaN;
DataN(Data > 0) = NaN;
figure;
stem(DataP,'k');
hold on;
stem(DataN,'b');
Data = [1,-2,3,1,-1,-2 4 2 3];
DataP = Data;
DataN = Data;
DataP(Data < 0) = NaN;
DataN(Data > 0) = NaN;
figure;
stem(DataP,'k','fill');
hold on;
stem(DataN,'b','fill');
Data = [1,-2,3,1,-1,-2 4 2 3];
DataP = Data;
DataN = Data;
DataP(Data < 0) = NaN;
DataN(Data > 0) = NaN;
figure;
stem(DataP,':diamondk','fill');
hold on;
stem(DataN,':diamondr','fill');
Data = [1,-2,3,1,-1,-2 4 2 3];
DataP = Data;
DataN = Data;
DataP(Data < 0) = NaN;
DataN(Data > 0) = NaN;
figure;
stem(DataP,'LineStyle','-.','MarkerFaceColor','k','MarkerEdgeColor','green'); hold on;
stem(DataN,'LineStyle','-.','MarkerFaceColor','red','MarkerEdgeColor','green');
三维图形
figure;
[X,Y] = meshgrid(-15:.5:15,-12:.5:12);
%X belongs to [-15,15] and Y belongs to [-12,12]. R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R;
mesh(Z); %surf(X,Y,Z)
xlabel('X','FontSize',14,'FontName','Times New Roman') ylabel('Y','FontSize',14,'FontName','Times New Roman') zlabel('Z','FontSize',14,'FontName','Times New Roman')
title('3-D space','FontSize',16,'FontName','Times New Roman')
figure;
X=-12:0.5:12;Y=-12:0.5:12;
%surf 绘图时,X,Y 可以是一维向量,也可以是二维矩阵 R=ones(length(X),length(Y)); for i=1:length(X)
for j=1:length(Y)
R(i,j) = sqrt(X(i).^2 + Y(j).^2) +eps; end end
Z = sin(R)./R; surf(X,Y,Z);
xlabel('X','FontSize',14,'FontName','Times New Roman') ylabel('Y','FontSize',14,'FontName','Times New Roman') zlabel('Z','FontSize',14,'FontName','Times New Roman')
title('3-D space by surf','FontSize',16,'FontName','Times New Roman')
X
3-D space by mesh
Y
Z
figure;
[X,Y] = meshgrid(-15:.5:15,-12:.5:12);
%X belongs to [-15,15] and Y belongs to [-12,12]. R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; plot3(X,Y,Z);
xlabel('X','FontSize',14,'FontName','Times New Roman') ylabel('Y','FontSize',14,'FontName','Times New Roman') zlabel('Z','FontSize',14,'FontName','Times New Roman')
title('3-D space by plot3','FontSize',16,'FontName','Times New Roman')
X
3-D space by surf
Y
Z
X
3-D space by plot3
Z
数学公式、符号和希腊字母的输入命令
Character Sequence Symbol Character
Sequence
Symbol Character
Sequence
Symbol
\alphaα\upsilonυ\sim~ \betaβ\phiΦ\leq≤\gammaγ\chiχ\infty∞\deltaδ\psiψ\clubsuit♣\epsilonɛ\omegaω\diamondsuit♦\zetaζ\GammaΓ\heartsuit♥\etaη\DeltaΔ\spadesuit♠\thetaΘ\ThetaΘ\leftrightarrow↔\varthetaϑ\LambdaΛ\leftarrow←\iotaι\XiΞ\uparrow↑\kappaκ\PiΠ\rightarrow→\lambdaλ\SigmaΣ\downarrow↓\muµ\Upsilonϒ\circº\nuν\PhiΦ\pm±\xiξ\PsiΨ\geq≥\piπ\OmegaΩ\propto∝\rhoρ\forall∀\partial∂\sigmaσ\exists∃\bullet•\varsigmaς\ni∍\div÷\tauτ\cong≅\neq≠\equiv≡\approx≈\alephℵ\Imℑ\Reℜ\wp℘\otimes⊗\oplus⊕\oslash∅\cap∩\cup∪\supseteq⊇\supset⊃\subseteq⊆\subset⊂\int∫\in∈\oο\rfloorë\lceilé\nabla∇\lfloorû\cdot·\ldots... \perp⊥\neg¬\prime´\wedge∧\times x\0∅\rceilù\surd√\mid| \vee∨\varpiϖ\copyright©\langle∠\rangle∠
图形标注
set(gca,'FontSize',10, 'FontName','Arial')
xlabel('test','FontSize',10,'FontName','Arial')
ylabel('test','FontSize',10,'FontName','Arial')
legend('test','FontSize',10,'FontName','Arial')
title('test','FontSize',13,'FontName','Times New Roman')
r(red)红色G(green) 绿色 b(blue) 蓝色c(cyan) 青色
M(magenta) 品红y(yellow) 黄色 k(black) 黑色w(white) 白色+ 加号o(字母) 小圆圈* 星号. 实点x 叉号
d 棱形^ 上三角形v 下三角形
colormap(jet)
坐标控制
axis函数的调用格式为:
axis([xmin xmax ymin ymax zmin zmax])
axis square:产生正方形坐标系(缺省为矩形)
axis auto:使用缺省设置
axis off:取消坐标轴
axis on:显示坐标轴
grid on:加网格线。

相关文档
最新文档