Re: COLORBAR label too long [message #55351] |
Sat, 18 August 2007 06:43 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> My suggestion would be to use a program like NUMBER_FORMATTER,
> which takes some of the mystery out of what you are going
> to end up with. Or, alternatively, you can convert your numbers to
> strings with the STRING function and the proper FORMAT
> keyword. (Good luck!)
>
> http://www.dfanning.com/programs/number_formatter.pro
While this suggestion could be followed, it was a little
awkward, since NUMBER_FORMATTER was not set up to accept
arrays of numbers. Plus, this discussion pointed out a
couple of unanticipated weaknesses in the program. All
of these deficiencies have been addressed this morning.
You can find a new version in the usual place. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: COLORBAR label too long [message #55353 is a reply to message #55351] |
Fri, 17 August 2007 14:03  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ryan. writes:
> All of a sudden I am getting labels with 4 digits after the decimal.
> So now they are overlapping one another. Before I didn't have any.
> Does anyone know why this would happen? It worked fine after I put in
> the STRTRIM function and then I was working on something else (my
> function that created the particular color table for this routine). I
> know this is vague but am I missing any intricacy of IDL or did I
> accidentally change something?
>
> ticks = StrTrim((SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2) ,
> 2) <- David's line of code
> ticks = STRTRIM((SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2) ,
> 2) <- My line of code
This all has to do with the "natural length" of a number
and how these numbers are converted to strings. It can be
a mess. :-)
My guess is that one of your numbers changed from an
integer to a float, and it is that number you are using
in your strings.
My suggestion would be to use a program like NUMBER_FORMATTER,
which takes some of the mystery out of what you are going
to end up with. Or, alternatively, you can convert your numbers to
strings with the STRING function and the proper FORMAT
keyword. (Good luck!)
http://www.dfanning.com/programs/number_formatter.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: COLORBAR label too long [message #55354 is a reply to message #55353] |
Fri, 17 August 2007 13:36  |
rchughes
Messages: 26 Registered: April 2006
|
Junior Member |
|
|
All of a sudden I am getting labels with 4 digits after the decimal.
So now they are overlapping one another. Before I didn't have any.
Does anyone know why this would happen? It worked fine after I put in
the STRTRIM function and then I was working on something else (my
function that created the particular color table for this routine). I
know this is vague but am I missing any intricacy of IDL or did I
accidentally change something?
ticks = StrTrim((SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2) ,
2) <- David's line of code
ticks = STRTRIM((SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2) ,
2) <- My line of code
Thanks,
Ryan.
|
|
|
|
Re: COLORBAR label too long [message #55356 is a reply to message #55355] |
Fri, 17 August 2007 11:10  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ryan. writes:
> I have created a nice-looking plot with a color bar on the top but the
> labels extend too far past the end of the bar. My plot is positioned
> in the bottom 80% of the window and the color bar is in the top 20%
> (using the POSITION keywords). The array of values I give to the
> COLORBAR procedure extends beyond the end of the bar.
>
> Here is my code:
> PLOT, FINDGEN(10), POSITION=[0.05, 0.05, 0.95, 0.82]
>
> ticks = (SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2)
>
> COLORBAR, BOTTOM=0, NCOLORS=clrTableLength, /TOP, $
> TICKNAMES=ticks, COLOR=black, DIVISIONS=(clrTableLength/5), $
> POSITION=[0.07, 0.87, 0.93, 0.95]
>
> 'clrTableLength' is the length of a color table I created. Currently
> I am using a table of length 100 (i.e. clrTableLength=100)
Your strings are longer than you think they are. :-)
Try this command instead:
ticks = StrTrim((SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2) ,2)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: COLORBAR label too long [message #55357 is a reply to message #55356] |
Fri, 17 August 2007 10:54  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Ryan. wrote:
> Dear All,
>
> I have created a nice-looking plot with a color bar on the top but the
> labels extend too far past the end of the bar. My plot is positioned
> in the bottom 80% of the window and the color bar is in the top 20%
> (using the POSITION keywords). The array of values I give to the
> COLORBAR procedure extends beyond the end of the bar.
>
> Here is a diagram of what happens:
>
> 1 2 3 4 5 6 7 8 9 0 <-labels
> ---------------------
> --------------------- <-colorbar
> ____________
> | |
> | | <-plot
> | |
> |___________ |
>
> Here is my code:
> PLOT, FINDGEN(10), POSITION=[0.05, 0.05, 0.95, 0.82]
>
> ticks = (SINDGEN((clrTableLength/5)+1)*5)-(clrTableLength/2)
>
> COLORBAR, BOTTOM=0, NCOLORS=clrTableLength, /TOP, $
> TICKNAMES=ticks, COLOR=black, DIVISIONS=(clrTableLength/5), $
> POSITION=[0.07, 0.87, 0.93, 0.95]
>
> 'clrTableLength' is the length of a color table I created. Currently
> I am using a table of length 100 (i.e. clrTableLength=100)
Shouldn't "divisions" = (clrTableLength/5)+1 ?
cheers,
paulv
|
|
|
|