Search code examples
matlabmatlab-figure

How to resolve the overlapping Ytick labels in probplot, Matlab?


I am trying to plot a log normal distribution using the matlab function, probplot. But while I do, i am getting an overlap in the yticklabelsenter image description here.

I would need that much of a font size (40). Is there a way to eliminate overlaps by providing custom yticklabels esp. with the probplot function ? Please note that the yticklabels for probplot is not straightforward.

Please find the test data in the following link

The code is as follows :

TestData=importdata('TestData.txt');

h1=probplot('lognormal',TestData,'noref');
set(h1(1),'marker','d','color','b','markersize',8,'markerfacecolor','b');
set(gca,'fontsize',40);

Solution

  • It appears that the labels on the y axis are not directly the values on that axis

    >> get(gca, 'ytick')
    ans =
       -3.7190   -1.6449   -1.2816   -0.6745         0    0.6745    1.2816 ...
    

    but rather

    >> normcdf(get(gca, 'ytick'))
    ans =
        0.0001    0.0500    0.1000    0.2500    0.5000    0.7500    0.9000 ...    
    

    (the number -1.2816 gave it away that normcdf was involved). Therefore, the labels can be obtained from the values using norminv. For example,

    >> norminv(.0001)
    ans =
       -3.7190
    

    Thus, to specify a set of desired values, use this after the plot has been created:

    desired_values = [.0001 .005 .05 .25 .75 .95 .995 .9999];
    set(gca, 'ytick', norminv(desired_values), 'yticklabels', desired_values);
    

    Example

    Let

    TestData = exp(randn(1,1e5)); % example data
    

    Before (that is, plot obtained from your code):

    enter image description here

    After (that is, using my code on the above plot):

    enter image description here