Fanning Software Consulting

Making Room for a Plot Title

QUESTION: I want to use a second X axis on my plot, but if I do there is no room for a plot title, since the annotation of the second axis overwrites it. Are there keywords to control the placement of the plot title? If not, how can I get a title on my plot?

ANSWER: There are no keywords to control the location of the plot title, so you will have to put the title on the plot yourself with XYOUTS. Typically, the plot title is 1.25 times the standard character size. To center the title appropriately, you will use the !X.Window system variable. You leave some room for the plot title by using the POSITION keyword to position the plot in your output window. Your code will look something like this:

   data = Loaddata(1)
   Plot, data, XStyle=8, Position=[0.15, 0.15, 0.9, 0.85], $
      XTitle='1st X Title', YTitle='Y Title'
   Axis, XAxis=1, XRange=[0,15], /Save, XTitle='2nd X Title'
   x = (!X.Window[1] - !X.Window[0]) / 2. + !X.Window[0]
   y = 0.92
   XYOuts, x, y, 'This is the Plot Title', /Normal, Alignment=0.5, Charsize=1.25

A plot with a title added with XYOUTS.

[Return to IDL Programming Tips]