首页 > 编程知识 正文

pyplot设置坐标轴大小,matlab的plot的线型

时间:2023-05-05 23:21:34 阅读:200128 作者:3453

展开全部

1、axis equal

2、这个功能matlab无法直接实现,除非是用最新的R2015b版本。因此,有人写了一个自定义函数 shift_axis_to_origin( ) 实现将坐标轴移到原点62616964757a686964616fe78988e69d8331333337626139的效果。function shift_axis_to_origin( fig_handle )

% 本函数目的是把 matlab 做的图坐标轴移到图形的中间部分去(与数学的做图习惯一致)

% 2008.10.10 in pku

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

xL=xlim ;

yL=ylim ;

xt=get(gca,'xtick') ;

yt=get(gca,'ytick') ;

set(gca,'XTick',[],'XColor','w') ;

set(gca,'YTick',[],'YColor','w') ;

% 把 x 和 y 坐标轴的两个方向各延长 10% (为了视觉上好看)

extend_x = ( xL(2)-xL(1) ) * 0.1 ;

extend_y = ( yL(2)-yL(1) ) * 0.1 ;

xxL = xL + [ -extend_x extend_x] ;

yyL = yL + [ -extend_y extend_y] ;

set(gca,'xlim', xxL) ;

set(gca,'ylim', yyL) ;

pos = get(gca,'Position') ;

% box off;

x_shift = abs( yyL(1)/(yyL(2)-yyL(1)) ) ;

y_shift = abs( xxL(1)/(xxL(2)-xxL(1)) ) ;

temp_1 = axes( 'Position', pos + [ 0 , pos(4) * x_shift , 0 , - pos(4)* x_shift*0.99999 ] ) ;

xlim(xxL) ;

% box off ;

set(temp_1,'XTick',xt,'Color','None','YTick',[]) ;

set(temp_1,'YColor','w') ;

temp_2 = axes( 'Position', pos + [ pos(3) * y_shift , 0 , -pos(3)* y_shift*0.99999 , 0 ] ) ;

ylim(yyL) ;

% box off ;

set(temp_2,'YTick',yt,'Color','None','XTick',[]) ;

set(temp_2,'XColor','w') ;

Base_pos = get(fig_handle,'Position') ;

arrow_pos_in_x_dircetion = Base_pos(2) - Base_pos(4) * yyL(1)/(yyL(2)-yyL(1)) ;

arrow_pos_in_y_dircetion = Base_pos(1) - Base_pos(3) * xxL(1)/(xxL(2)-xxL(1)) ;

annotation('arrow',[Base_pos(1) , Base_pos(1)+Base_pos(3)] , [arrow_pos_in_x_dircetion , arrow_pos_in_x_dircetion ] , 'Color','k');

annotation('arrow',[arrow_pos_in_y_dircetion , arrow_pos_in_y_dircetion ] , [Base_pos(2) , Base_pos(2)+Base_pos(4)] , 'Color','k');

end

将上面的函数保存在工作目录下,通过以下代码基本可以实现你的需求% 原来的代码

F=@(p,x)p(1)*x(:,1).^2+p(2)*x(:,1).*x(:,2)+p(3)*x(:,2).^2+p(4);

% 离散数据点

x=load('C:UserskkkDesktopTotal.txt');

p0=[1 1 1 1];

warning off

% 拟合系数,最wmdhxc乘方法

p=nlinfit(x,zeros(size(x,1),1),F,p0);

plot(x(:,1),x(:,2),'ro');

hold on;

xmin=min(x(:,1));

xmax=max(x(:,1));

ymin=min(x(:,2));

ymax=max(x(:,2));

% 作图

ezplot(@(x,y)F(p,[x,y]),[-1+xmin,1+xmax,-1+ymin,1+ymax]);

title('曲线拟合');

legend('样本点','拟合曲线')

% 新增代码

xlabel('')

ylabel('')

shift_axis_to_origin( gca ) ;

axis equal

最终效果

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。