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

Re: draw text parallel to a sloping line

Vinay L. Kashyap (kashyap@head-cfa.harvard.edu) writes:

> It doesn't work because >orientation< in XYOUTS does not know
> anything about the previous PLOT and the data ranges in the
> plot.  Do the following:
> X = 24.5259  & Y = 16789.1 & Slope = -1763.03 ; data coordinates
> dX=2.2 & plot, [X-dX,X+dX], Y+[-dX,dX]*Slope
> 	;{convert slope from data to device coordinates
> DATA_XY=convert_coord(X+DX*[-1,1],Y+DX*SLOPE*[-1,1],/DATA,/TO_DEVICE)
> O_angle=atan(DATA_DY,DATA_DX)*!radeg
> 	;end changes}
> xyouts,X,Y,'A_String_Parallel_To_A_Line',align=0.5,orient=O_angle

Well, the solution is correct. But I think the explanation
could use a little work. :-)

It is not that XYOUTS doesn't "know anything" about the previous
PLOT. It certainly does know, by virtue of the !X.S and !Y.S
scaling parameters that get set by the PLOT command. Rather,
it is not the angle in data coordinate space we want here. It
is the angle of the text on the display. And you are correct
that we have to make the conversion from data space to
device space in order to properly calculate that angle.


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