matlab畫圖:設置y軸位置,使y軸在x軸的中間


sigmoid函數圖像 

x=-10:0.1:10;  y=sigmf(x,[1 0]);  plot(x,y)

畫出的圖像如下所示:

怎么將Y軸放在中間呢,而不是在左邊?

即如何得到這種效果呢?

方法:新建一個函數:xyplot.m

%作用:將Y坐標軸放在中間
function xyplot(x,y)
% PLOT
if nargin>0
if nargin == 2
plot(x,y);
else
display(' Not 2D Data set !')
end
end
hold on;
% GET TICKS
X=get(gca,'Xtick');
Y=get(gca,'Ytick');
% GET LABELS
XL=get(gca,'XtickLabel');
YL=get(gca,'YtickLabel');
% GET OFFSETS
Xoff=diff(get(gca,'XLim'))./40;
Yoff=diff(get(gca,'YLim'))./40;
% DRAW AXIS LINEs
plot(get(gca,'XLim'),[0 0],'k');
plot([0 0],get(gca,'YLim'),'k');
% Plot new ticks
for i=1:length(X)
plot([X(i) X(i)],[0 Yoff],'-k');
end;
for i=1:length(Y)
plot([Xoff, 0],[Y(i) Y(i)],'-k');
end;
% ADD LABELS
text(X,zeros(size(X))-2.*Yoff,XL);
text(zeros(size(Y))-3.*Xoff,Y,YL);
box off;
% axis square;
axis off;
set(gcf,'color','w');
set(gca,'FontSize',20);

運行完代碼

x=-10:0.1:10;  y=sigmf(x,[1 0]);  plot(x,y)

之后

輸入 xyplot 即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM