文章目录
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轴坐标描述