[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: line graph problems
Brian wrote:
>
> Hello,
>
> I have a couple of problems I was hoping that someone might be able to
> help me with...
>
> First of all I am trying to automate the process of creating a series
> of line graphs for a project (approximately 50). I could do this in
> Excel, but it is very time consuming. I was hoping to use IDL to make
> the process easier, but it seems to be causing me just as many
> headaches.
>
> There will be two plots per page and they have identical y-axis and
> variable x-axis ranges. The x-axis values are fairly large, which
> leads me to my first problem. Is it possible to change the text
> orientation for an axis using PLOT? I've searched the IDL help and
> David's book and can't seem to find any reference to this. I'd like
> to have the text display at a 45 degree angel so the values don't
> overlap when displayed.
My solution to exactly this problem (but for 7x4 plots per page) is avoid like the plague
anything that requires shifting plot/tick titles. IDL makes this an unbelievable difficult
process - particularly if you're going to automate it so it has to work in a fairly robust
manner (as opposed to a one off mucking about about with POSITION and XYOUTS and god-knows
what). I prefer to scale the data as follows:
max_exponent = 0
scale_check = ( ( MACHAR( /DOUBLE ) ).EPS )^2
maxval = ABS( MIN( xdata ) > MAX( xdata )
multiplier = 1.0d
xtitle = 'X Data'
IF ( maxval GT scale_check ) THEN BEGIN
exponent = FLOOR( ALOG10( maxval ) )
IF ( ABS(exponent) GT max_exponent ) THEN BEGIN
multiplier = 10.0d^(-exponent)
xtitle = 'X Data (x'+STRING(10.0d^(exponent),FORMAT='(e7.1)')+')'
ENDIF
ENDIF
PLOT, multiplier * xdata, ydata, $
XTITLE = xtitle, $
YTITLE = 'Y Data'
This "dynamically" scales the data and updates the x-axis title with the scale factor.
Depending on what you like, you can change the max_exponent. I prefer anything larger or
equal to 10 to be scaled. It has worked flawlessly for me so far (touch wood) with no
overlapping x-tick labels.
> My second problem relates to the y-axis. In
> several of my plots I have a few y values that are large while the
> rest are many times smaller. Is it possible to create a broken y-axis
> so I can bring out the smaller values while still displaying the
> larger ones?
This is a hairier problem but I would recommend steering away from doing what you suggest
(i.e. what other plotting/graphics packages do with ease - broken y-axis) at least with
IDL. Can you scale the data again in this case? E.g. plot the y-data on a logarithmic axis
(won't work if values < or = 0). If it can be done, then you can use the following as the
X|YTICKFORMAT keyword function name to avoid gobs of unneeded decimal places, e.g.
1000.00000 if the smallest tick label is 0.00001 (which I find _extremely_ annoying):
FUNCTION logticks, axis, index, value
exponent = LONG( ALOG10( value ) )
CASE 1 OF
; -- Exponent is less than zero ->
; -- fractional ticklabel
( exponent LT 0 ): format = '( f' + $
STRTRIM( ABS( exponent ) + 2, 2 ) + $
'.' + $
STRTRIM( ABS( exponent ), 2 ) + $
' )'
; -- Exponent is greater than or = to zero ->
; -- whole number ticklabel
( exponent GE 0 ): format = '( i' + $
STRTRIM( ABS( exponent ) + 1, 2 ) + $
' )'
ENDCASE
RETURN, STRING( value, FORMAT = format )
END
Hope some of this is useful.
paulv
--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
paul.vandelst@noaa.gov Alexander Pope.