Y2 axis title orientation [message #74681] |
Fri, 28 January 2011 10:47  |
Jonathan
Messages: 8 Registered: January 2011
|
Junior Member |
|
|
I have been occasionally frustrated by the inability to title a Y2
axis (y-axis on the right side of a plot) with the right orientation.
Using the command:
AXIS,/SAVE,YAXIS=1,TITLE='title'
writes the title with the baseline on the right, rather than the left.
The latter is how I have always seen and used y2 axis titles, and it
is a strange quirk of IDL that it insists on doing this in a non-
standard (and in fact ugly) way.
Today, I finally wrote a routine to correct this. I do not promise
that it is perfect, but I hope it is a step in the right direction,
and that with input from users of this group we can finally make a
usable y2 axis title routine.
Here it is ...
;+
; NAME:
; Y2TITLE
;
; PURPOSE:
; The purpose of this routine is to print a right-hand y-axis
title
; with the baseline towards the axis (IDL's baseline is away
from the axis).
;
; AUTHOR:
;
; Jonathan Friedman
; NAIC Arecibo Observatory
; HC-3 Box 53995
; Arecibo, PR 00612
; http://www.naic.edu
; e-mail: jonathan@naic.edu
;
; CATEGORY:
; Plotting, annotation and labeling.
;
; CALLING SEQUENCE:
; Y2TITLE(titletext)
;
; INPUTS:
; titletext: The text that you want to use for the Y2 title.
;
; KEYWORD PARAMETERS:
;
; ANGLE: An angle for the text, CCW from vertical + baseline
to the left
; in degrees.
;
; CHARSIZE: The character size of the title. Default is 1.0.
;
; COLOR: The color index of the title. Default is !P.Color..
;
; FONT: Sets the font of the annotation. Hershey: -1,
Hardware:0, True-Type: 1.
;
;
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; The title is relative to the most recent PLOT call.
;
; RESTRICTIONS:
; none.
;
; EXAMPLE:
; To display a y2 title, type:
;
; x=findgen(100)
; y1=sin(2*!pi*x/30)
; y2=5.*cos(2*!pi*x/45 + 0.6)
; PLOT,x,y1,YRANGE=[-1,1],YSTYLE=3,YTITLE='SIN(2!4p!3x/30)'
; AXIS,/SAVE,YAXIS=1,YRANGE=[-5,5],YSTYLE=3
; OPLOT,x,y2,linestyle=2
; Y2TITLE('5.0*COS(2!4p!3x/45 + 0.6)')
;
; MODIFICATION HISTORY:
; Written by: Jonathan Friedman, 28 January 2011.
;-
;
;########################################################### ################
;
; LICENSE
;
;
; Copyright
;
; This software is provided "as-is", without any express or
; implied warranty. In no event will the authors be held liable
; for any damages arising from the use of this software.
;
; Permission is granted to anyone to use this software for any
; purpose, including commercial applications, and to alter it and
; redistribute it freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must
; not claim you wrote the original software. If you use this
software
; in a product, an acknowledgment in the product documentation
; would be appreciated, but is not required.
;
; 2. Altered source versions must be plainly marked as such, and must
; not be misrepresented as being the original software.
;
; 3. This notice may not be removed or altered from any source
distribution.
;
;
;########################################################### ################
PRO y2title, text,ANGLE=angle,CHARSIZE=charsize,COLOR=color,FONT=font
IF NOT KEYWORD_SET(ANGLE) then angle=0
; coordinates of the plotting window in /NORMAL
x0 = !x.window[0]
x1 = !x.window[1]
y0 = !y.window[0]
y1 = !y.window[1]
ch_nwidth = FLOAT(!D.X_CH_SIZE)/FLOAT(!D.X_VSIZE)
; Determine the width of the y2 axis labels, and set the
; position of the y2 axis title to the right of the labels.
ylabel_val = ABS(!Y.CRANGE[1]) > ABS(!Y.CRANGE[0])
ofs = (MIN(!Y.CRANGE) LT 0)? 3:2
label_nwidth = CEIL(ABS(ALOG10(ylabel_val))) + ofs
cs = (!P.CHARSIZE GT 0) ? !P.CHARSIZE*ch_nwidth : ch_nwidth
xpos = (x1 + 0.01*(x1-x0)) + label_nwidth*cs
ypos = (y1 + y0)/2
XYOUTS,xpos,ypos,text,/NORMAL,ALIGNMENT=0.5, $
ORIENTATION=270+angle, $
CHARSIZE=charsize, COLOR=color, FONT=font
END
|
|
|