数学建模实战Matlab绘图

二维曲线、散点图

绘图命令:plot(x,y,'line specifiers','PropertyName',PropertyValue)

例子:绘图表示年收入与年份的关系

'--r*':--设置线型;r:设置颜色为红色;*节点型号

'linewidth':设置线宽;'markersize':节点大小

常用命令:hold on(off):在一张图上持续绘图

或者也可使用命令:line()

图的标注

xlabel('text'):x轴标签

ylabel('text'):y轴标签

title('text'):标题

text(x,y,'text'):图内文字

gtext('text'):指定位置的文字

legend('str1','str2',...,pos):图例区分

其中,pos可取值:

-1:图例外置于右侧

0:图例内置于最佳位置

1:右上 2:左上 3:左下 4:右下

对数坐标轴

复制代码
function epx_plt1
    years=1994:2000;
    income=[8 12 20 22 18 24 27];
    plot(years,income,'--r*','linewidth',2,'markersize',12)
end

x=-2:0.01:4;
y=3*x.^3-26*x+6;
y2=9*x.^2-25;
y3=17*x;

plot(x,y,'-b');
hold on;
plot(x,y2,'--g');
plot(x,y3,'-.r');
hold off;

x=10:0.1:22;
y=95450./x.^2;
x2=10:2:22;
y2=[950 640 460 340 250 180 140];
plot(x,y,'-','linewidth',1)
xlabel('Distance(cm)')
ylabel('Intensity(lux)')
title('','fontsize',14);
axis([8 24 0 1200]);
text(14,700,'Comparison between theory and experiment.','edgecolor','r','linewidth',2);

hold on
plot(x2,y2,'ro--','linewidth',1,'markersize',10);
legend('Theory','Experiment');
hold off;

figure
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
plot(x,y);

figure
semilogx(x,y);
相关推荐
时间的情敌13 小时前
Three.js 射线拾取进阶:hover 高亮、点击弹窗、多物体过滤、穿透拾取
开发语言·javascript·three.js
Amumu1213814 小时前
TypeScript学习: 基本类型(一)
开发语言·前端·typescript
敲上瘾15 小时前
Qt 常用控件:按钮、显示输入、容器与布局等
开发语言·c++·qt·qt6.3
船神丿男人15 小时前
C++ STL 入门:用 std::string 读配置,四个容易漏掉的边界
开发语言·c++
3095566661 天前
股票接口重试怎么分类:正常、空数组与错误响应的幂等处理
java·大数据·开发语言·数据库·php·api接口·股票数据api接口
YLCHUP1 天前
【括号匹配+dp优化】题解:双端括号(brackets)_动态规划_状态优化_数学建模_贪心_性质挖掘_STLmap_C++算法竞赛
数据结构·c++·笔记·算法·数学建模·贪心算法·动态规划
郝学胜-神的一滴1 天前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
geovindu1 天前
python:Logistic Regression
开发语言·后端·python·算法
摇滚侠1 天前
《On Java 中文版 基础卷》阅读笔记 内部类 21
java·开发语言·笔记