MATLAB画图修改格式语句大全(实时更新)
文章目录
图像
图像大小和位置
set(gcf,'unit','centimeters','position',[10 5 16 16]);
set(gca,'Position',[0.2 0.2 0.55 0.55]);
边框宽度设置
set(gca,'linewidth',2)
legend
例如要人为确定需要在legend的线段后空出多少字符格:
lgd = legend('p1 on','p2 on')
lgd.TextColor = 'white'
改变坐标轴的刻度以及范围
set(gca,'xlim',[-998,-992.4]);
set(gca,'XTick',[-998:0.01/0.005:-992.4]) ;
set(gca,'ylim',[0.6,1.4]);
set(gca,'YTick',[0.6:0.4:1.4]) ;
参考:https://blog.csdn.net/XTU__zhang/article/details/116270944
对数坐标
semilogx / semilogy:如果出现对数是负数,则MATLAB2019不支持,2021支持。
三维图可以用:set(gca,‘XScale’,‘log’,‘YScale’,‘log’); %三维时需要加ZScale
参考:
https://ww2.mathworks.cn/help/matlab/ref/semilogy.html
https://blog.csdn.net/weixin_39509073/article/details/124854221
colorbar相关
边框宽度
colorbar('linewidth',2) %colorbar的边框宽度
colorbar标注
'reverse’是将colorbar刻度线反向设置
'out’是将colorbar刻度线外移(看起来更明显), 三种形式:in; out; inout
caxis([0.2,1.7]) %colorbar范围
colorbar('Ticks',[0.5 1 1.5],'TickLabels',{'0.5','1','1.5'},'LineWidth',2,'Direction','reverse','TickDirection','out'); %colorbar值显示
箭头型坐标轴
画箭头
annotation('arrow',[0.132 0.132],[0.11 0.96],'LineWidth',2);
annotation('arrow',[0.132 0.93],[0.11 0.11],'LineWidth',2);
annotation('doublearrow',[0.518 0.518],[0.46 0.58]);
xlabel('');
ylabel('');
标注位置
set(gca, 'XTick', [5 14]) ;
set(gca,'XTickLabel',{'0','\delta'});
set(gca, 'YTick', [13 15]) ;
set(gca,'YTickLabel',{'E','(b)'});
set(gca,'FontName','Times New Roman','FontSize',20)
删去网格
set(gca,'XGrid','off'); %隐藏轴网格线
box off %去除坐标区周围的框轮廓
实现相关语句
close all; clear all; clc
x=[-2:0.01:12];
a=1;
b=1;
c=sqrt(a^2+b^2);
y1=sqrt((x-5).^2/b.^2+2)*a+5;
y2=-sqrt((x-5).^2/b.^2+2)*a+5;
p=find(y1==min(y1));
q=find(y2==max(y2));
plot(x,y1,'red','LineWidth',2);
hold on;
plot(x,y2,'red','LineWidth',2);
hold on;
plot([5,5],[max(y2),min(y1)],'color',[0,0,0],'LineWidth',2);
text(x(p)-4,y1(p)+1,['|1>'],'color','b','FontSize',15,'FontWeight','bold')
text(x(q)-4,y2(q)-1,['|0>'],'color','b','FontSize',15,'FontWeight','bold')
text(5.5,5,['2t'],'color','b','FontSize',15,'FontWeight','bold')