用subplot画图后,如何在每个子图下方添加标题,直接用title,则显示的内容是在默认的图形上方,而不是在图形的下方。若要求在每个图形下方加标题,如一幅图中用subplot画了3个子图,如何在每个子图下方加标题, 该怎么实现呢? |
可用xlabel。
x=linspace(0,2*pi,30); y=sin(x); z=cos(x);
u=2*sin(x).*cos(x); v=sin(x)./cos(x);
subplot(2,2,1),plot(x,y),axis([0 2*pi -1 1]),xlabel('sin(x)')
subplot(2,2,2),plot(x,z),axis([0 2*pi -1 1]), xlabel ('cos(x)')
subplot(2,2,3),plot(x,u),axis([0 2*pi -1 1]), xlabel ('2sin(x)cos(x)')
subplot(2,2,4),plot(x,v),axis([0 2*pi -20 20]), xlabel ('sin(x)/cos(x)')
title('position',[x,y]),x,y为你想加入的坐标,改变标题的位置。 |
% time sequence
clear all; clc; close all;
t = 0:0.01:7;
% plot
subplot(4,1,1);
cla; hold on; box on;
plot(t, sin(t), 'r');
grid on;
subplot(4,1,2);
cla; hold on; box on;
plot(t, cos(t), 'r');
grid on;
subplot(4,1,3);
cla; hold on; box on
plot(t, 2*sin(t), 'r');
grid on;
subplot(4,1,4);
cla; hold on; box on
plot(t, 2*cos(t), 'r');
grid on;
% save figure
message = sprintf('Now, save the figure.');
uiwait(msgbox(message));
saveas(gcf,'1.fig');
% close figure
message = sprintf('Close the figure.');
uiwait(msgbox(message));
close all;
% open figure
message = sprintf('Open the figure.');
uiwait(msgbox(message));
open 1.fig
hold all;
sublist = get(gcf, 'children');
% re-plot
message = sprintf('Plot the figure without erasering the old plot.');
uiwait(msgbox(message));
hold on;
plot(sublist(4), t, cos(t), 'g');
hold on;
plot(sublist(3), t, sin(t), 'g');
hold on;
plot(sublist(2), t, 2*cos(t), 'g');
hold on;
plot(sublist(1), t, 2*sin(t), 'g');