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

Home » Public Forums » archive » Re: Histogram has wrong x-axis?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Histogram has wrong x-axis? [message #10862] Fri, 13 February 1998 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Bruce Bowler (bowler@eisner.decus.org) writes:

> I'm fairly new to IDL so I'm probably missing something obvious...

It's pretty obvious, but I think you are in good company by
feeling confused by it. :-)

> I have a big (1024x1024) array that has a minimum value of -16.1 and a maximum
> value of 4.1. When I PLOT, HISTOGRAM(array), the x axis ranges form 0-20, why
> isn't the X axis range -17 to 5?

The PLOT command can actually take two arguments. Here
you are passing it only one, the return value of the HISTOGRAM
function. If you pass a single argument to the PLOT command
the PLOT command assumes this is the dependent data (the
data that is to be plotted on the Y axis). Since you didn't
supply the independent data, IDL creates a vector that has
as the same number of elements as the dependent data to use
as the independent data set. In this case that vector is
a 20 element array ranging in value from 0 to 19. So these
commands:

histData = HISTOGRAM(array)
PLOT, histData

Are exactly the same as these commands:

histData = HISTOGRAM(array)
depData = FINDGEN(N_ELEMENTS(histData))
PLOT, depData, histData

(Notice that if you supply two arguments to the PLOT command
that the first argument is the independent data and the second
argument is the dependent data. This has always seemed strange
to me, but there you have it.)

What you would like is for the dependent data vector to reflect
the actual values in your data set rather than the number of
elements in the independent data. So you need to write code
like this:

histData = HISTOGRAM(array)
num = N_ELEMENTS(histData)
depData = FINDGEN(num) * ((MAX(array) - MIN(array))/(num-1)) $
+ MIN(array)
PLOT, depData, histData

If you want the X axis to *just* cover the data range, set
the XSTYLE keyword to 1 on the PLOT command.

You can find more information about these kinds of plotting
details in my IDL Programming Techniques book.

Cheers,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Previous Topic: Re: Compound widget help
Next Topic: Re: Tick labels in object graphics

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

Current Time: Sun Oct 12 10:33:29 PDT 2025

Total time taken to generate the page: 1.03926 seconds