建模可视化代码总结

1 python读写txt文件

1.1 读txt

infile=open("d://1.txt",'r')
m=[]
for line in infile:
    m.append(line)
infile.close()
print(m)

1.2 写txt

利用writelines()函数或者write函数

infile=open("d://1.txt",'r')
outfile=open("d://2.txt",'w')
m=[]
for line in infile:
    m.append(line)
infile.close()
#print(m) 
#print(len(m))
#for i in range(len(m)):
outfile.writelines(m)
outfile.close()

或是

infile=open("d://1.txt",'r')
outfile=open("d://2.txt",'w')
m=[]
for line in infile:
    m.append(line)
infile.close()
#print(m) 
#print(len(m))
for i in range(len(m)):
    outfile.write(m[i])
outfile.close()

2 matlab柱形图

clear;clc;
x=[1 2 3 4 5 6 7 8];

y1=[60 51 83 69 96 61 100 61];
y2=[92 46 63 95 98 54 98 60];
y_all=[y1;y2]';%设置两列
bar(x,y_all)
title('10-Training and 50-Testing')
xlabel('Class')
ylabel('Accuracy')
legend('SVM','NN')
set(gca,'xticklabel',{'Hyt','Maple','Su','Zm','Bob','Hly','Hhf','Yq'});

3 matlab二维曲线

clear all
x=linspace(0,2*pi,50);
y1=sin(x);
y2=cos(x);
y3=tan(x); 
figure(1);
subplot(3,1,1);
plot(x,y1,'--or') %坐标点为圆圈标志,且线型为红色短划线的绘图样式
axis([0 2*pi -2 2]);
xlabel('x');
ylabel('y');
subplot(3,1,2);
plot(x,y2,'gp--');
axis([0 2*pi -2 2]);
legend('cos','Location','North')
subplot(3,1,3);
plot(x,y3,'-.vy');
axis([0 2*pi -2 2]);
title('My Title');

在这里插入图片描述

类型符号类型符号类型符号
黄色y实线-实点标记.
紫色m(magenta)点线:圆圈标记o
青色c(cyan)点画线-.叉号形x
红色r(red)虚线十字形+
绿色g(green)星号*向上三角形^
蓝色b(blue)方块s向左<
白色w(white)钻石形d向右>
黑色k(black)向下三角形v五角星标记p

3 matlab三维曲线

参数方程形式

clear all
t=linspace(0,20,2000);
x=sin(t);
y=cos(t);
plot3(x,y,t)
grid on

在这里插入图片描述

4 matlab三维图

clear all
x=-5:0.01:5;
y=-8:0.01:8;
[X,Y]=meshgrid(x,y);%网络化变量
R=sqrt(X.^2+Y.^2);
Z=sin(R)./R;
mesh(X,Y,Z)%三维网线图形

在这里插入图片描述

热力图

clear all
x=-5:0.01:5;
y=-8:0.01:8;
z=sqrt(x.^2+3.*y.^2+10);
maxx=max(x);
%取x的最小值
minx=min(x);
%同x
maxy=max(y);
miny=min(y);
%生成网格
[X,Y]=meshgrid(linspace(minx,maxx),linspace(miny,maxy));
%插入热值
Z=griddata(x,y,z,X,Y,'v4');
subplot(1,2,1);
%生成三维面
mesh(X,Y,Z)
hold on
%在三维面上画出热值、颜色
plot3(x,y,z,'r.')
hold on
%坐标命名
xlabel('X-长度');
ylabel('Y-宽度');
zlabel('Z-热值');
%插入颜色条
colorbar
%二维视角
subplot(1,2,2);
%生成三维面
mesh(X,Y,Z)
hold on
%在三维面上画出人员密度值,高低峰岁值的大小而改变,颜色也是
plot3(x,y,z,'r.')
hold on
view(2);
%坐标命名
xlabel('X-长度');
ylabel('Y-宽度');
zlabel('Z-热值');
%插入颜色条
colorbar

在这里插入图片描述

5 matlab折线图

选自https://blog.csdn.net/u012318074/article/details/79894443

clear all;
x=1:1:5;%x轴上的数据,第一个值代表数据开始,第二个值代表间隔,第三个值代表终止
a=[203.024,113.857,256.259,244.888,293.376]; %a数据y值
b=[334.4,143.2,297.4,487.2,596.2]; %b数据y值
plot(x,a,'-*b',x,b,'-or'); %线性,颜色,标记
axis([0,6,0,700])  %确定x轴与y轴框图大小
set(gca,'XTick',[0:1:6]) %x轴范围1-6,间隔1
set(gca,'YTick',[0:100:700]) %y轴范围0-700,间隔100
legend('Neo4j','MongoDB');   %右上角标注
xlabel('深度')  %x轴坐标描述
ylabel('时间(ms)') %y轴坐标描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值