《隐秘的角落》:张东升老师,你的“心形线”画错了喔!教你Matlab画出高逼格图像!
clc ;close all
theta=-pi:0.001:pi;
r=10*(1-sin(theta));
polar(theta,r,'r')
静态心形线:
ezplot('x^2+(y-(x^2)^(1/3))^2=9')
动态心形线:
clc;
clear;
a=20;
x=-2:0.01:2;
figure(1);
set(gcf,'position',[0,0,800,600],'color','w');
for i=1:200;
str_title = strcat('\color{red}a=',num2str(a));
y=abs(x).^(2/3)+(0.9*sqrt((3.3-x.^2))).*sin(a*pi*x);
a = i/10;
figure(i);
set(gcf,'position',[0,0,800,600],'color','w');
p1=plot(x,y,'r','LineWidth',3);
hold on;
title('\color{red}f(x)=x^2^/^3+e/3*(π-x^2)^1^/^2*sin(a*π*x)','fontsize',15);
text(-0.2,2.3,str_title,'FontName','Times New Roman','FontSize',20);
xlim([-2 2]);
ylim([-1.5 2.5]);
frame = getframe(gcf);
im=frame2im(frame);
[I,map]=rgb2ind(im,256);
if i==1
imwrite(I,map,'心.gif','gif','Loopcount',Inf,'DelayTime',0.05);
%imwrite函数将动图保存为GIF
else
imwrite(I,map,'心.gif','gif','WriteMode','append','DelayTime',0.05);
end
close(figure(i));
end
三维立体心形线:
clc
close all
meshgrid(linspace(-1.3,1.3)); =
val=(x.^2 + (9/4)*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9/80)*y.^2.*z.^3;
isosurface(x,y,z,val,0)
axis equal
view(-10,24)
colormap flag
camlight
lighting phong
说正事,划重点!
以正余弦曲线为例:
%部分代码,详细代码关注公众号
close all;clear;
x=0:0.1:4*pi;
y=sin(x);
y1=cos(x-pi/6);
plot(x,y,'bo-')%设置线型、标记符、颜色(b为蓝色,o为圆圈,-为实线),引号中三者不区分前后位置
hold on
plot(x,y1,'r*-')%设置线型、标记符、颜色(b为蓝色,*为星号,-为实线),引号中三者不区分前后位置
详细线型、标记符、颜色设置不用记忆,收藏好,直接查找下表就好啦!
axis on; %设置坐标轴开启
axis([0 4*pi -1 1]);%显示坐标轴范围,x轴为[0,4*pi],y轴为[-1,1]
set(gca,'xtick',0:1:4*pi);%gca是当前坐标轴的句柄,xtick表示我要设置x轴刻度要显示的位置
set(gca,'ytick',-1:0.2:1,'Fontname','Times New Roman');%xtick表示我要设置y轴刻度要显示的位置
xlabel('\itx','FontSize',15,'Fontname','Times New Roman');%设置横轴标签、字号、字体
ylabel('\ity','FontSize',15,'Fontname','Times New Roman');%设置纵轴标签、字号、字体
I=legend('y=sin(x)','y=cos(x-\pi/6)','FontSize',12,'Location','Northeast')%设置图例,并设置字体、位置。适合一幅图内多条曲线
I.FontName='Times New Roman';%此处可设置其他中文字体
title('正余弦曲线','Fontname','宋体');%设置标题
text(pi,sin(pi),'\leftarrowy=sin(x)','Fontname','Times New Roman','HorizontalAlignment','left')%设置要标注的数据点或者曲线
text(9/5*pi,cos(9/5*pi-pi/6),'y=cos(x-\pi/6)\rightarrow','Fontname','Times New Roman','HorizontalAlignment','right')%设置要标注的数据点或者曲线
grid on%添加网格线
saveas(gcf,'正余弦曲线.svg')%保存绘制好的图像至当先文件夹,图片推荐svg矢量图格式,或者tiff无损压缩格式,保存更清晰喔
公众号 |
小编微信 |
B站 |
QQ群 |
点赞 8 评论 1 收藏 3