How to change the font size of the x axis?

Is there a way to change the font size property of the x-axis in MATLAB for a shape? I need to resize the values ​​along the x axis (not the header, which can be changed using the xlabel property). I have the following code snippet:

 %% Some figure properties: width=15;height=20;alw=0.75; %% Figure: for i=1:8 figure;set(gcf,'color','white'); pos=get(gcf, 'Position'); set(gcf, 'Position', [pos(1) pos(2) width*100, height*100]); set(gca, 'LineWidth', alw);axis off; axes('position',[0.06 0.08 0.87 0.38]) plot(0:24,s(i).obs(:,1),'linewidth',2,'color','b');hold on; plot(0:24,s(i).sim(:,1)-273.15,'linewidth',2,'color','r'); legend('Obs','Sim','location','northeastoutside'); set(gca,'xtick',0:24,'xticklabel',0:24); set(gca,'ytick',2:2:28,'yticklabel',2:2:28); xlabel('Hour');ylabel('[°C]');axis([0 24 2 28]);grid on; axes('position',[0.06 0.53 0.87 0.38]); plot(s(i).time.obs,s(i).serie.obs,'b');hold on; plot(s(i).time.sim,s(i).serie.sim-273.15,'r'); datetick('x','myy');axis tight;grid on; legend('Obs','Sim','location','northeastoutside'); title([s(i).name ', porcNaN: ' num2str(roundn(s(i).rnan,-1)) ... '%, period: ' datestr(s(i).period(1,:),20) ' - '... datestr(s(i).period(2,:),20)],'fontsize',12); ylabel('[°C]');set(gca,'fontsize',8) image_name=['temp_sup_' s(i).name]; print(image_name,'-dpng','-r600') end 

"s" is a structure. The problem is the x-axis values ​​of the second graph (figure above), the datetick sets all the months and years, I need this information (every month), but they are very close to each other. I know the fontsize property, but this property changes the font size to two axes (x and y), and I only need to change the x axis.

+3
source share
1 answer

I always do this as follows:

 plot(X) set(gca, 'FontName', 'Arial') set(gca, 'FontSize', 12) ylabel('Label Y axis') xlabel('Label X axis') 

Thus, the axis and label will have the required font and size. It is very important to put 'xlabel' and 'ylabel' after 'set' . Order in this case matters.

There is another way to set fonts for xlabel, ylable, legend, plot, as shown below; it can complement the top answer:

 % Define values linewidthnumber = 2; legendfontsize = 12; labelfontsize = 12; axisfontsize = 12; custom_plot_handle_name = plot(x); custom_legend_handle_name = legend(); custom_x_label_name = xlabel(); custom_y_label_name = ylabel(); % Set the parameters now to the given values set(h, 'Linewidth', linewidthnumber); set(custom_legen_handle_name,'FontSize', legendfontsize); set(custom_x_label_name, 'FontSize', labelfontsize); set(custom_y_label_name, 'FontSize', labelfontsize); set(gca, 'FontSize', axisfontsize); 
+9
source

Source: https://habr.com/ru/post/1412166/


All Articles