繪制y=x^2,並添加直角坐標軸。
clear;clc;close all %% 繪制方程 x = -10:0.01:10; figure; y = x.^2-30; plot(x,y,'k','linewidth',2) axis off set(gcf,'Position',[100 100 360 420]); w1 = min(y); w2 = max(y); %% 繪制坐標軸 xlim = max(abs(x)); ylim = max(abs([w1 w2])); axis(gca,[-xlim xlim -ylim ylim]); xx = get(gca,'xtick'); yy = get(gca,'ytick'); dx = mean(diff(yy))/5; dy = mean(diff(xx))/5; axis(gca,[-xlim xlim -ylim ylim]); set(gca,'units','normalized'); pos1 = get(gca,'position'); s1 = [pos1(1) pos1(2)+pos1(4)/2]; s2 = [pos1(1)+pos1(3) pos1(2)+pos1(4)/2]; s3 = [pos1(1)+pos1(3)/2 pos1(2)]; s4 = [pos1(1)+pos1(3)/2 pos1(2)+pos1(4)]; annotation('arrow',[s1(1) s2(1)],[s1(2) s2(2)]) annotation('arrow',[s3(1) s4(1)],[s3(2) s4(2)]) % 顯示坐標軸標注 text(max(x)-2,-2,'x') % 自己動手調整 text(1,max(y)-2,'y') % 自己動手調整 text(-1,-2,'0') % 自己動手調整 %% 保存圖片 saveas(gcf,'pic.png')