0
votes

Log plots in MATLAB only label the axes at positions 10^x, where x is an integer (e.g., 10^4, 10^5, 10^6). Sometimes, one may want labels at intermediate sites or minor ticks (e.g., 5*10^4, 5*10^5).

In order to place such labels, I have resorted to using the text command with appropriate x and y coordinates. However, the font of the superscript in the text command differs from that in the default axis label. This is true even if the font for axis label and text is set to be identical by the following:

set(0,'DefaultAxesFontName','Helvetica');
set(0,'DefaultTextFontName','Helvetica');
set(0,'DefaultTextFontSize',15);
set(0,'DefaultAxesFontSize',15);

In particular, the superscript font size appears to be smaller in the default axis label compared to the text box. Is there a way to resolve this discrepancy so that the font in the text box and the font in the axis label are identical (including superscripts)?

1

1 Answers

1
votes

You can set the x and y axis points like this:

figure
set(gca,'xtick',10.^[0.5:0.5:3])
set(gca,'ytick',10.^[0.5:0.5:3])

gives you steps in 0.5 log 10. There is also an attribute called xticklabel

EDIT: Here's a complete example using arbitrary labels, scientific notation:

semilogx([2:100:10e4],[2:100:10e4])
axis([2 2e4 2 10000])
xticks=10.^[0.5:0.5:10]';
al={};
for i = 1:length(xticks)
       tmps=sprintf("%1.1e}",xticks(i));
       tmps=strrep(tmps,"e","x10^{");  # replace e with x10^{
       tmps=strrep(tmps,"+0","");      # +0 does not add any info
       tmps=strrep(tmps,"-0","-");     # -0123 into -123 
       tmps=strrep(tmps,"+","");       # + does not add any info
       al(i)=tmps;
end
set(gca,'xtick',xticks);
set(gca,'xticklabel',al)