##消除白边
LooseInset是Matlab坐标轴的一个隐藏属性,其默认值是[0.13, 0.11, 0.095, 0.075],从而为刻度标记留出一定的空间。若将其清零,则可以消除白边。
set(gca, 'LooseInset', [0,0,0,0]);
##绘图速查表
一维数据
二维数据
位置说明
通过axes()命令可以改变坐标的默认位置
text()命令中的对齐选项,可以更轻松准确地在途中放置字符串
##Marker的使用
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
p1 = plot(x,y1,'->','MarkerIndices',1:5:length(y1));%每5个数据点标记一次
hold on
p2 = plot(x,y2,'-o','MarkerIndices',[1 50 100]);%在第一个,第5个,第10个位置标记
p1(1).LineWidth = 2;%设置第一个线条的线宽为2磅
p2(1).LineWidth = 2;%设置第二个线条的线宽为2磅
##图形属性的设置
可以使用对象属性的方式来设置,比较有层次感
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
p(1).LineWidth = 2;%设置第一个线条的线宽为2磅
p(2).Marker = '>';%设置第二个线条的标记marker为'>'
p(2).LineWidth = 2;%设置第二个线条的线宽为2磅
p(1).Color = 'm';%对颜色进行设置
p(2).Color = 'r';%对颜色进行设置
p = plot(x,y1,x,y2);
##MATLAB使用LATEX 公式
这里的’interpreter’的意思为选择解释器的语法, 其后跟Latex
’
.
.
.
...
...’ 是指放在行内的公式;’$$…$$是指单独占据一行或几行的公式
- 标题加LATEX公式
figure(1); % 标题中添加LateX格式公式
x = 0.1:0.1:10;
plot(x, sin(x)./x);
title('$\frac{sin(x)}{x}$','interpreter','latex', 'FontSize', 18);
set(gcf, 'position', [0 0 400 300]);
- 在图例中插入LateX公式
单个图例
figure(1); % 图例中添加LateX格式公式
x = 0.1:0.1:10;
plot(x, sin(x)./x);
handle = legend('$\frac{sin(x)}{x}$');
set(handle,'Interpreter','latex', 'FontSize', 18)
多个图例
这样可以同时设置图例的LATEX公式
figure(1); % 图例中添加LateX格式公式
x = 0.1:0.1:10;
plot(x, sin(x)./x,x,2*sin(x)./x);
handle = legend('$\frac{sin(x)}{x}$','$\frac{2*sin(x)}{x}$');
set(handle,'Interpreter','latex', 'FontSize', 18)
- 在坐标轴中插入LateX公式
figure(1); % 坐标轴中添加LateX格式公式
alpha = 0.1:0.1:10; beta = sin(x)./x;
plot(alpha, beta);
xlabel('$\alpha$','interpreter','latex', 'FontSize', 18);
ylabel('$\beta$','interpreter','latex', 'FontSize', 18);