[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotating tick labels

TomC (tom_syn58@hotmail.com) writes:

> I am using IDL 5.4 to create PostScript files of plain old X-Y plots. Some
> of the plots have usernames as the x-axis tick labels. When there are lots
> of users, or long names and lots of users, the labels overwrite each other,
> creating an un-readable mess. Is there an easy way to have the tick labels
> created at an angle? Thanks in advance.

I have a short section in my book about how this can be done.
I was going to take it out of the 2nd Edition because I was
trying to save pages and I thought "who would ever need to
know how to do this?". But at the last minute I left it in.
You never know. :-)

Anyway, if you mean by "easy" some kind of keyword switch,
then the answer is "no". But is is not too hard either.

Suppose you are going to have 5 tick intervals, labeled
with 6 tick labels on the X axis:

  numticks = 5
  labels = ['One', 'Two', 'Three', 'Four', 'Five', 'Six']

Draw the plot, leaving some room for the rotated labels:

   Plot, findgen(11), XTickFormat='(A1)', XStyle=1, $
     XTicks=numticks, Position=[0.1, 0.2, 0.85, 0.95]

Calculate positions for the labels:

   ypos = Replicate(!Y.Window[0] - 0.04, numticks+1)
   xpos = !X.Window[0] + (!X.Window[1] - !X.Window[0]) * $
      Findgen(numticks + 1) / numticks

Position the labels:

   FOR j=0, numticks DO XYOutS, xpos[j], ypos[j], $
      labels[j], Alignment=0.0, Orientation=-45, /Normal



David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155