您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何在matlab中設(shè)置xlabel,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
xlabel(‘time',‘FontSize',12);
如果沒有設(shè)置位置,默認(rèn)是在中間
xlabel(‘time',‘position',[900,1870],‘FontSize',12);
此時(shí)‘time'在你設(shè)置的位置
pos=axis;%取得當(dāng)前坐標(biāo)軸的范圍,即[xmin xmax ymin ymax] xlabel(‘time',‘FontSize',12, ‘Position',[pos(2) pos(3)]) x=0:pi/50:2*pi; y=sin(x); plot(x,y); pos=axis;%取得當(dāng)前坐標(biāo)軸的范圍,即[xmin xmax ymin ymax] xlabel('x軸','position',[pos(2) 1.15*pos(3)]);%設(shè)置x軸標(biāo)簽的文本在圖的右下方,1.15這個(gè)值根據(jù)自己的需要可以調(diào)整 形成的圖
補(bǔ)充:Matlab作圖實(shí)例——xlabel,ylabel,title,text,plot,patch,datetime等的應(yīng)用
所用數(shù)據(jù)如下:
代碼如下:
clear clc format compact format shortG T = readtable('repayment_schedule.xlsx','ReadVariableNames',true) T.time=datetime(datestr(T.time,'yyyy.mm.dd'),'InputFormat','yyyy.MM.dd',... 'format','yyyy.MM.dd') p=plot(T.time,T.m_per_month,T.time,T.m_residue) p(1).Marker='o' p(2).Marker='*' box off %讓y軸不用科學(xué)計(jì)數(shù)法顯示 h=gca y_val=h.YTick y_str=string(y_val) %等價(jià)于y_str=num2str(y_val') h.YTickLabel=y_str %橫軸日期顯示設(shè)置 h.XTick=T.time xtickangle(45) %讓x軸的標(biāo)簽?zāi)鏁r(shí)針旋轉(zhuǎn)45度 %畫垂直虛線 hold on p1=plot([datetime(2018,11,20) datetime(2018,11,20)],... [0 30830],'Color',[0.6 0.6 0.6],'LineStyle','--') p2=plot([datetime(2018,12,20) datetime(2018,12,20)],... [0 26434],'Color',[0.6 0.6 0.6],'LineStyle','--') p3=plot([datetime(2019,01,20) datetime(2019,01,20)],... [0 22038],'Color',[0.6 0.6 0.6],'LineStyle','--') p4=plot([datetime(2019,02,20) datetime(2019,02,20)],... [0 17641],'Color',[0.6 0.6 0.6],'LineStyle','--') p5=plot([datetime(2019,03,20) datetime(2019,03,20)],... [0 13245],'Color',[0.6 0.6 0.6],'LineStyle','--') p6=plot([datetime(2019,04,20) datetime(2019,04,20)],... [0 8849],'Color',[0.6 0.6 0.6],'LineStyle','--') p7=plot([datetime(2019,05,20) datetime(2019,05,20)],... [0 4452.8],'Color',[0.6 0.6 0.6],'LineStyle','--') hold off %標(biāo)注每個(gè)點(diǎn) str1=string(T.m_per_month) str2=string(T.m_residue) text(T.time,T.m_per_month-1200,str1,'Color',[0 0.447 0.741],... 'HorizontalAlignment','center') text(datetime(datenum(T.time)+2,'ConvertFrom','datenum'),... T.m_residue+1100,str2,... 'Color',[0.85 0.325 0.098],... 'HorizontalAlignment','left') %圖例 legend([p(1) p(2)],{'每月還款金額','每月還款后剩余總本息'},... 'Location','northeast','NumColumns',1) %各個(gè)標(biāo)題 xlabel('還款時(shí)間') ylabel('還款金額') title({'GGG還款計(jì)劃';'2018.12.20-2019.06.20'}) print('GGG還款計(jì)劃','-dpdf') %將數(shù)據(jù)再寫入excel % writetable(T,'test.xlsx','WriteVariableNames',true)
做出的圖如下:
相應(yīng)代碼為:
%填充并畫網(wǎng)格 clear clc v1 = [0 0; 4 0; 4 4;0 4]; f1 = [1 2 3 4]; figure patch('Faces',f1,'Vertices',v1,... 'EdgeColor',[0.75 0.75 0.75],'FaceColor',[0.75 0.75 0.75]); g=gca g.XTick=[0:4] g.YTick=[0:4] g.XLim=[0 4.5] g.YLim=[0 4.5] grid on g.Layer = 'top'; g.GridColor=[1 1 1] g.GridLineStyle='--' g.GridAlpha = 1 axis square %挖洞 v2 = [1 1;2 1;2 2;1 2]; f2 = [1 2 3 4]; patch('Faces',f2,'Vertices',v2,... 'EdgeColor',[0.75 0.75 0.75],'FaceColor',[1 1 1]); %畫函數(shù)圖 hold on f1=@(t) 4*t-4 f2=@(t) 0.25*t+1 f1p=fplot(f1,[1 2],'k','LineWidth',1,'DisplayName','X的策略') f2p=fplot(f2,[0 4],'--k','LineWidth',1,'DisplayName','Y的策略') xlabel('X的策略') ylabel('Y的策略') legend([f1p f2p],{},'NumColumns',2,'FontSize',10) %導(dǎo)出為PDF % saveas(gcf,'qiyan.pdf') print('qiyan','-dpdf')
做出的圖如下
關(guān)于如何在matlab中設(shè)置xlabel就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。