matlab画图技巧,[转载]MATLAB 图形控制技巧

振动论坛的ChaChing大神的个人主页上有许多连接以说明各种图形控制方法:

引用几条:

1、axes标注的多种方法:

fplot('exp(-x)',[0 7],'r');hold on;

fplot(@(x) sin(x),[0 7],'b.');

legend('y=(1+1/x)^x','alpha_1^{Psi_0+delta^3}+e^{-jw_0t}','Location','best');

set(gca,'Xtick',(1:1:7),'Xticklabel',{'Matlab','讨','论','区','欢','迎','您'},...

'Color','white','FontWeight',' bold ');

text(.2,-0.2,{'振','动','论','坛'},'FontSize',20','Color',[1 0 0]);

text(1,0.3,'标注演示^{花如月}_{ID:63517}','FontSize',18','Color',[0.8 0.2

1]);

text(4.5,-0.2,{'勇','创','佳','绩'},'FontSize',20','Color',[0 0

1]);

93000201_1

2、多图统一放置于一张图中,不用subplot的样式

n=1:512; t=n.*0.02;

x1=sin(t); x2=cos(2*t); x3=x1+x2;

z=[x1,x2,x3];

strips(z,length(x1));

set(gca,'YTickLabel',[]);

% set(gca,'YTickLabel',[0,0,0]) %

或全为0

然后使用命令活的y轴的上下区间,计算出每个图片框的位置的Y值,设置Ylabel在对应位置为0即可;

93000201_2

3、多图统一放置于一张图中,方法2:

使用hold on操作。

每绘制完成一张图后,将下一组Y值数据全部加上一个常数,使此图位于上一张图之上,再下一个图时都加上某一个常数,这样在纵轴上就有所区分了。

此法还可以实现不用的图使用的Y值范围不一样,从而可以缩放图片和绘制不同高度的图片。

hold on

b_length = size(b,1) % 取得矩陣大小 = 取得有幾條線

for i = 1:b_length

plot(a,b(i,:)+k*i)

end

set(gca,'YLim',[0 b_length*k+k]) % 設定邊界

set(gca,'YTick',k:k:b_length*k) %

設定 顯示哪些刻度

set(gca,'YTickLabel',1:b_length) % 將顯示刻度變成 1 2 3 4 5

....

93000201_3

4、多纵坐标画图

function [ax,hlines] = plotyyy(x1,y1,x2,y2,x3,y3,ylabels)

%PLOTYYY - Extends plotyy to include a third

y-axis

%

%Syntax: [ax,hlines] =

plotyyy(x1,y1,x2,y2,x3,y3,ylabels)

%

%Inputs: x1,y1 are the xdata and ydata for the first axes'

line

% x2,y2 are the xdata and ydata for the second axes' line

% x3,y3 are the xdata and ydata for the third axes' line

% ylabels is a 3x1 cell array containing the ylabel strings

%

%Outputs: ax

- 3x1 double array containing the axes' handles

% hlines - 3x1 double array containing the lines' handles

%

%Example:

%x=0:10;

%y1=x; y2=x.^2; y3=x.^3;

%ylabels{1}='First y-label';

%ylabels{2}='Second y-label';

%ylabels{3}='Third y-label';

%[ax,hlines] = plotyyy(x,y1,x,y2,x,y3,ylabels);

%legend(hlines, 'y = x','y = x^2','y = x^3',2)

%

%m-files required: none

%Author: Denis Gilbert, Ph.D., physical

oceanography

%Maurice Lamontagne Institute

pt. of Fisheries and Oceans Canada

%email: gilbertd@dfo-mpo.gc.ca%Web: http://www.qc.dfo-mpo.gc.ca/iml/

%April 2000; Last revision:

14-Nov-2001

if nargin==6

%Use empty strings for the

ylabels

ylabels{1}=' '; ylabels{2}='

'; ylabels{3}=' ';

elseif nargin > 7

error('Too many input

arguments')

elseif nargin < 6

error('Not enough input

arguments')

end

figure('units','normalized',...

'DefaultAxesXMinorTick','on','DefaultAxesYminorTick','on');

% Plot the first two lines with

plotyy

[ax,hlines(1),hlines(2)] = plotyy(x1,y1,x2,y2);

cfig = get(gcf,'color');

pos = [0.1 0.1 0.7 0.8];

offset = pos(3)/5.5;

% Reduce width of the two axes generated

by plotyy

pos(3) = pos(3) - offset/2;

set(ax,'position',pos);

% Determine the position of the third

axes

pos3=[pos(1) pos(2) pos(3)+offset pos(4)];

termine the proper x-limits for the third axes

limx1=get(ax(1),'xlim');

limx3=[limx1(1) limx1(1) +

1.2*(limx1(2)-limx1(1))];

% Bug fix 14 Nov-2001: the 1.2 scale factor

in the line above

% was contributed by Mariano Garcia (BorgWarner Morse TEC

Inc)

ax(3)=axes('Position',pos3,'box','off',...

'Color','none','XColor','k','YColor','r',... 'xtick',[],'xlim',limx3,'yaxislocation','right');

hlines(3) = line(x3,y3,'Color','r','Parent',ax(3));

limy3=get(ax(3),'YLim');

% Hide unwanted portion of the x-axis line

that lies

% between the end of the second and third

axesline([limx1(2) limx3(2)],[limy3(1)

limy3(1)],...

'Color',cfig,'Parent',ax(3),'Clipping','off');

axes(ax(2))

% Label all three y-axes

set(get(ax(1),'ylabel'),'string',ylabels{1})

set(get(ax(2),'ylabel'),'string',ylabels{2})

set(get(ax(3),'ylabel'),'string',ylabels{3})

93000201_4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值