一、背景
在matlab使用plot函數繪圖后,生成的圖片坐標軸數字字體大小及間隔可能并不符合我們的要求,因此需要自定義修改,具體方法如下
二、修改坐標軸數字字體大小
只需添加以下命令即可:
set(gca,'FontName','Times New Roman','FontSize',18);
不僅可以修改坐標軸數字字體大小,還可以修改字體類型
三、自定義坐標軸間隔
只需添加以下命令即可:
xticks(0:5:20);
該命令的意思為橫坐標區(qū)間為0-20,間隔5取值
四、一個簡單的例子
clear, close all,clc;
a1 = subplot( 1, 1, 1 );
hold( a1, 'on' );
x = linspace(0,10);
y1 = sin(x);
y2 = cos(x);
A1 = plot( a1, x, y1, 'linewidth', 5, 'color', [0.0000, 0.4470, 0.7410] );
A2 = plot( a1, x, y2, 'linewidth', 3, 'linestyle', '--', 'color', 'm' );
set( a1, 'xlim', [0, 10], 'fontsize', 25, 'xticklabel', {0:2:10} )
title( a1, 'X-Position', 'Fontsize', 30)
xticks(0:2:10);
xlabel( 'Time(step)', 'Fontsize', 17)
ylabel( '$ y $ position','Interpreter','latex', 'Fontsize', 19)
set(gca,'FontName','Times New Roman','FontSize',18)
scatter( a1, 0, sin(0), 100, 'filled', 'linewidth', 1, 'markerfacecolor', 'y', 'markeredgecolor', 'k' );
scatter( a1, 10, sin(10), 100, 'filled', 'linewidth', 1, 'markerfacecolor', 'g', 'markeredgecolor', 'k' );
legend([A1,A2],'sin(x)','cos(x)','Location','SouthEast')
legend('boxoff')
未經修改坐標軸數字字體大小及坐標軸間隔前,看起來很丑是不是:
經過修改坐標軸數字字體大小及坐標軸自定義間隔后,看起來美觀許多:文章來源:http://www.zghlxwxcb.cn/news/detail-791882.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-791882.html
到了這里,關于matlab繪圖修改坐標軸數字字體大小及坐標軸自定義間隔設置的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!