2

I'm having a problem getting the title to set for some loglog plots in Matlab. The title function works fine when plotting the same data using plot(x,y), but fails to display when using loglog(x,y). I thought it might be a bug triggered by the data, but it looks like I was wrong - please see the commenting below.

%title_prob
figure
x=0:1:1000;                     
y=3*x.^x;                       %The sum of this vecor is Inf
loglog(x,y)
title('Title','FontSize',16)    %This title doesn't set
xlabel('X Label','FontSize',12)
ylabel('Y Label','FontSize',12)

figure
x2=0:1:100;
y2=3*x2.^x2;                    %The sum of this vector is finite
loglog(x2,y2)
title('Title','FontSize',16)    %This title does set
xlabel('X Label','FontSize',12)
ylabel('Y Label','FontSize',12)

%Further investigation - is Inf to blame?  Apparently not.
FirstInf=max(find(y<Inf))+1;
figure
loglog(x(1:FirstInf),y(1:FirstInf))
title('Inf value in the y vector','FontSize',16)    %Title not set

figure
loglog(x(1:FirstInf-1),y(1:FirstInf-1))
title('NO Inf value in the y vector','FontSize',16) %Title not set
figure
plot(x,y)
title('Works for the plot function','FontSize',16)

Thanks for any suggestions.

4

2 回答 2

1
%Further investigation - is Inf to blame?  Apparently not.
FirstInf=max(find(y<Inf))+1;
figure
loglog(x(1:FirstInf),y(1:FirstInf))
title('Inf value in the y vector','FontSize',16)    %Title not set

Yes but you may have a NAN right there in the first position, in y(1). As 0^0 is undefined, so perhaps that is causing the anomaly.

Edit. Technically 0^0 is undefined because the limit depends upon which way you approach zero in the augmements. Lim x^0 (as x goes to zero from above) is 1, whereas lim 0^x (as x goes to zero) is 0. That's why it's technically undefined.

However I just checked in gnu-Octave and 0^0 returned 1 without any issues. So probably Matlab returns the same. So I guess this isn't the answer, but I'll leave it here anyway as someone might be interested in the technical difficulties with 0^0.

于 2013-04-11T13:07:23.820 回答
1

Title position is always calculated in axes coordinates based on upper y limit. So if it's Inf the title position will be also Inf and it will not be visible.

When you are taking out the Inf value from y (figure 4), the next value is still very large, about 1e306. To calculate title's position MATLAB adds some number to upper y limit (little below 1.8e308, check by ylim) and it becomes Inf (1.8e308 is already Inf). Check double values limit with REALMAX.

You can check the title position with

get(get(gca,'title'),'position')

So, yes, it is Inf values that make your title disappear.

You can set the y axis limit manually before calling title:

yl = ylim;
ylim([yl(1), 10^302])
于 2013-04-11T15:50:34.507 回答