Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gap between xtitle and xaxis

    In the following code, the gap between the xtitle and the xaxis is unnecessarily large. How can I make it smaller? Thanks!
    Code:
    twoway ///
           (func y=100*normalden(x), range(-3 3) lw(vthick) lcolor(navy)) ///
           (pcarrowi 0 -1 0 +1, lcolor(gray) mcolor(gray)) (pcarrowi 0 +1 0 -1, lcolor(gray) mcolor(gray))  ///
           (pcarrowi 10 -0.5 10 +0.5, lcolor(gray) mcolor(gray)) (pcarrowi 10 +0.5 10 -0.5, lcolor(gray) mcolor(gray))  ///
     , xlab(-3(.2)3, grid angle(90)) ylab(0(10)40, grid) legend(off) ///
       ytitle("Density", size(large)) xtitle("Standard deviations (Z) from the mean", size(large)) xscale(titlegap(1rs)) ///
       title("The standard normal probability density") ///
       subtitle("gives the slope of the cumulative standard normal distribution") ///
       text(2 0 "68%") text(12 0 "38%")

  • #2
    You already have the solution:

    xscale(titlegap( ))

    Comment


    • #3
      No, in this example xscale(titlegap( )) makes no difference to how far the xtitle is from the xaxis. At least for me. Do you see something different?

      Comment


      • #4
        This is what I get (Stata 18, and if you're using a previous version you're asked to state that, although I doubt version will bite any way).

        It looks fine to me in terms of title gap.

        I would use fewer labels on the x axis and display them horizontally, but that is a different question. Nor do I get why you've multiplied the density by 100 and still call it the density: same comment.

        Click image for larger version

Name:	whatever.png
Views:	1
Size:	81.7 KB
ID:	1746918

        Comment


        • #5
          Ah, I'm using Stata 16.1, and this is what I see. Quite a large space between xaxis and xtitle. I'll try upgrading to 18, see if that helps....
          Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	108.8 KB
ID:	1746926

          Comment


          • #6
            Stata 18 fixed a bug causing big gap between axis labels and axis title. When the number for the axis label is computed or is a number may not be exactly represented by a floating number, for example, soemthing like -1.4000000000000001, the graphics system has logic to display the label as -1.4, but the legenth of the label under some circumstances is wrongly computed based on -1.4000000000000001 instead of -1.4, which caused the overly big space allocated for the axis label, hence the big gap. In Stata 16, you may work around the bug by changing xlab(-3(.2)3, grid angle(90)) to xlab(-3(.5)3, grid angle(90)).
            Last edited by Hua Peng (StataCorp); 16 Mar 2024, 11:38.

            Comment


            • #7
              Thanks for the clarification Hua Peng (StataCorp) !
              I am working on getting an upgrade. Meanwhile is there a trick to get better results out of Stata 16 here?

              Comment


              • #8
                I just edited the reply, one wrok around for Stata 16 is to avoid non exactly representable floating number for the axis label, use xlab(-3(.5)3, grid angle(90)) instead of xlab(-3(.2)3, grid angle(90)). The other way is to use a format, something like xlab(-3(.2)3, format(%2.1f) grid angle(90)).
                Last edited by Hua Peng (StataCorp); 16 Mar 2024, 11:46.

                Comment


                • #9
                  Well, I got it to work in Stata 16.1. It turns out the problem only occurs when the tic labels are rotated 90 degrees. If I remove angle(90) from the code I originally posted, the problem disappears. To make the unrotated tic labels work, I reduced the number of tics, as Nick Cox suggested.

                  Now the revised code produces a nice-looking graph in Stata 16.1.
                  Code:
                  Code:
                  twoway ///
                         (scatteri 20 -.8 20 .8 80 .8 80 -.8, recast(area) color(gray*0.3) ) ///
                         (func y=100*normal(x), range(-3 3) lw(vthick) lcolor(navy)) ///
                         (func y=100*(1/2+.37*x), range(-.8 .8) lw(medthick) lpattern(dash) lcolor(yellow)) ///
                   , xlab(-2.8(.4)2.8, grid) ylab(0(10)100, grid) legend(off) ///
                     ytitle("Percentile (P)", size(large)) xtitle("Standard deviations (Z) from the mean", size(large)) ///
                     title("The cumulative standard normal distribution") ///
                     subtitle("is nearly linear, with slope 37, for Z=-0.8 to +0.8 (percentiles 21 to 79)")
                  Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	94.3 KB
ID:	1746932


                  Comment

                  Working...
                  X