comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Y2 axis title orientation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Y2 axis title orientation [message #74681] Fri, 28 January 2011 10:47 Go to next message
Jonathan is currently offline  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
Re: Y2 axis title orientation [message #74746 is a reply to message #74681] Mon, 31 January 2011 10:50 Go to previous message
Jonathan is currently offline  Jonathan
Messages: 8
Registered: January 2011
Junior Member
On Jan 31, 12:02 pm, David Fanning <n...@dfanning.com> wrote:
> David Fanning writes:
>> I don't think we have discovered the perfect algorithm
>> yet. This must be something that is written in a computer
>> algorithm book somewhere. I wish I knew where. :-(
>
> I think to do this correctly, you need access to the
> formatted tick labels. We don't this access, which is
> why we can't get things right.
>

I guess that means we are stuck with imperfect solutions. Anyway, it
is useful for me to have found a simple algorithm I can work with. In
the end, I almost always end up tweaking my output in Adobe
Illustrator.
--Jonathan
Re: Y2 axis title orientation [message #74749 is a reply to message #74681] Mon, 31 January 2011 08:02 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> I don't think we have discovered the perfect algorithm
> yet. This must be something that is written in a computer
> algorithm book somewhere. I wish I knew where. :-(

I think to do this correctly, you need access to the
formatted tick labels. We don't this access, which is
why we can't get things right.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Y2 axis title orientation [message #74750 is a reply to message #74681] Mon, 31 January 2011 07:57 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jonathan writes:

> When the title is on the right of the axis, IDL has it 180 degrees
> rotated from what I want. My routine fixes this.
> So, what I mean by baseline is, for example, where an underline of the
> text would be. I would want it on the left for the Y2 axis, but IDL
> would put it on the right. It is as though you used XYOUTS to create a
> title and, whereas IDL would have "ORIENTATION=90", I want
> "ORIENTATION=270". This is exactly what my code does, in fact.

I played with this a little bit over the weekend.
I don't know what algorithm IDL uses to position
the axis label, but I haven't discovered it yet.
This one is pretty good, but not perfect.

For example, set the axis range from -1.5 to 1.5. It
gets even worse if you change the character size on
the axis and title to something like 1.25.

When I have done this in the past (DCBAR, for example)
I've always have to provide a "fudge" to nudge the
placement here or there depending on circumstances.

I don't think we have discovered the perfect algorithm
yet. This must be something that is written in a computer
algorithm book somewhere. I wish I knew where. :-(

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Y2 axis title orientation [message #74751 is a reply to message #74681] Mon, 31 January 2011 07:48 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
OK, I think I get what you mean:
You would like the string with the title to be
displayed such that the string progresses from the
top to the bottom instead of going from the bottom
to the top.

In that case I believe there's no easy built-in way
to achieve that without using xyouts as you did.

Ciao,
Paolo


On Jan 31, 10:20 am, Jonathan <jonat...@naic.edu> wrote:
> Hi Paolo,
>
> When the title is on the right of the axis, IDL has it 180 degrees
> rotated from what I want. My routine fixes this.
> So, what I mean by baseline is, for example, where an underline of the
> text would be. I would want it on the left for the Y2 axis, but IDL
> would put it on the right. It is as though you used XYOUTS to create a
> title and, whereas IDL would have "ORIENTATION=90", I want
> "ORIENTATION=270". This is exactly what my code does, in fact.
>
> I hope that clears up your confusion. If not, I will post a graphic
> somewhere.
>
> Jonathan
> --
> On Jan 31, 10:57 am, Paolo <pgri...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> What do you mean as "baseline"? I see one title on the right
>> of the axis, and one title on the left of the axis, isn't that
>> what you wanted? If not what is it you need?
>
>> Ciao,
>> Paolo
Re: Y2 axis title orientation [message #74752 is a reply to message #74681] Mon, 31 January 2011 07:20 Go to previous message
Jonathan is currently offline  Jonathan
Messages: 8
Registered: January 2011
Junior Member
Hi Paolo,

When the title is on the right of the axis, IDL has it 180 degrees
rotated from what I want. My routine fixes this.
So, what I mean by baseline is, for example, where an underline of the
text would be. I would want it on the left for the Y2 axis, but IDL
would put it on the right. It is as though you used XYOUTS to create a
title and, whereas IDL would have "ORIENTATION=90", I want
"ORIENTATION=270". This is exactly what my code does, in fact.

I hope that clears up your confusion. If not, I will post a graphic
somewhere.

Jonathan
--
On Jan 31, 10:57 am, Paolo <pgri...@gmail.com> wrote:
>
> What do you mean as "baseline"? I see one title on the right
> of the axis, and one title on the left of the axis, isn't that
> what you wanted? If not what is it you need?
>
> Ciao,
> Paolo
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Y2 axis title orientation
Next Topic: Coyote Graphics Update, Monday Jan 31

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:36:25 PDT 2025

Total time taken to generate the page: 0.00771 seconds