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

Home » Public Forums » archive » Color Fonts?!?!?
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
Color Fonts?!?!? [message #30304] Wed, 17 April 2002 11:26 Go to next message
Sdavis is currently offline  Sdavis
Messages: 12
Registered: July 1998
Junior Member
Hey All,

Does anyone know how to make a string have different colored fonts. I
would like the x-axis title on a plot to have a string that has different
colors. thanks!

-sean

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>< ><><><><>
Sean M. Davis
___ o __ __ sdavis@nis.lanl.gov
|\/ o\ o ,,,, ) `-'. \ NIS-1
|/\___/ (::::[||||||||||||||#==#[| Los Alamos National Laboratory
'' ).-.__/ 505-667-8784
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>< ><><><><>
Re: Color Fonts?!?!? [message #30349 is a reply to message #30304] Thu, 18 April 2002 12:51 Go to previous messageGo to next message
Ken Mankoff is currently offline  Ken Mankoff
Messages: 158
Registered: February 2000
Senior Member
On Thu, 18 Apr 2002, Sean Davis wrote:
> So my question is, how would I know the correct positions to send to
> XYOUTS so that the xtitle appears in the same place as it would as if I
> had just called
>
> PLOT, findgen(20), xtitle='this is a cool title'

In english if you prefer that to code:

1) plot your data
2) get the length of your *full* title in NORMAL coords like this:
XYOUTS, 10, 10, title, /norm, width=width
3) get the x-axis range via the !x.crange word
4) translate (2) or (3) to either NORM or DATA coordinates
5) calculate the beginning of the position of the title
This is 1/2 of your axis range - 1/2 of the length of the title
6) split your title into 3 (or more parts)
7) for each part in (6) do (8)
8) XYOUTS a part of your title, and get the width it took. Translate
this width to whatever coord system you chose in (4).


Feel free to do the above with any charsize and charwidth you want.
Current limitations would be if you use logarithmic axis, and maybe if
your axis is negative, and probably if your axis increases to the
*left*, etc...

-k.
--
------------------------------------------------------------ ---------------
Ken Mankoff http://lasp.colorado.edu/snoe/
http://lasp.colorado.edu/mars/
http://lasp.colorado.edu/~mankoff/ http://lasp.colorado.edu/marsrobot/
------------------------------------------------------------ ---------------
Re: Color Fonts?!?!? [message #30350 is a reply to message #30304] Thu, 18 April 2002 12:38 Go to previous messageGo to next message
Ken Mankoff is currently offline  Ken Mankoff
Messages: 158
Registered: February 2000
Senior Member
On Thu, 18 Apr 2002, Sean Davis wrote:
> I'm not sure I understand how to find where the XTITLE would have been
> placed on the plot, in the monochrome case. If you knew where the XTITLE
> would have been placed, then it seems that using XYOUTS would work great.
>
> For example, the monochrome case would be
>
> PLOT, findgen(20), xtitle = 'This is a cool title'
>
> It seems to me you're saying that if I wanted the word 'cool' to be blue,
> I could do the following:
>
> 1. PLOT, findgen(20)
>
> 2. Break the title string into 3 strings
>
> 3. Make 3 calls to XYOUTS
>
> So my question is, how would I know the correct positions to send to
> XYOUTS so that the xtitle appears in the same place as it would as if I
> had just called
>
> PLOT, findgen(20), xtitle='this is a cool title'
>
> ???

The answer to your question is: "use the WIDTH= keyword from XYOUTS"

I put the code below into "title.pro", and call it this way:
IDL> title, findgen(20), 'This is a cool title', 'cool', chars=2, charth=3
IDL> plot, findgen(20), xtitle='This is a cool title', /NOERASE, $
chars=2, charth=3

NOTE: if you do not see any difference when overplot with the
PLOT,/NOERASE command, that is because on my computer it is producing
the *exact* same output...


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
PRO title, data, title, word, _EXTRA=e

;;; set up the plot
plot, data, _EXTRA=e

;;; get the length of the title
xyouts, 10, 10, title, /norm, width=width, _EXTRA=e
;;; calculate the middle of the X-AXIS of the plot
mid_axis_data = (!x.crange[1] + !x.crange[0]) / 2.
mid_axis_norm = $
(convert_coord([mid_axis_data,mid_axis_data],/data,/to_norm) )[0]
x_title = mid_axis_norm - (width/2.)

;;; set up the 3 titles
title_norm = strsplit( title, word, /extract, /regex )
title_color = word

;;; draw the 3 titles
xyouts, x_title, 0.02, title_norm[0], /norm, width=w0, _EXTRA=e
xyouts, x_title+w0, 0.02, title_color, /norm, width=w1, color=10, _EXTRA=e
xyouts, x_title+w0+w1, 0.02, title_norm[1], /norm, _EXTRA=e
END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;


--
------------------------------------------------------------ ---------------
Ken Mankoff http://lasp.colorado.edu/snoe/
http://lasp.colorado.edu/mars/
http://lasp.colorado.edu/~mankoff/ http://lasp.colorado.edu/marsrobot/
------------------------------------------------------------ ---------------
Re: Color Fonts?!?!? [message #30353 is a reply to message #30304] Thu, 18 April 2002 11:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Sean Davis (sdavis@nis.lanl.gov) writes:

> I'm not sure I understand how to find where the XTITLE would have been
> placed on the plot, in the monochrome case. If you knew where the XTITLE
> would have been placed, then it seems that using XYOUTS would work great.
>
> For example, the monochrome case would be
>
> PLOT, findgen(20), xtitle = 'This is a cool title'
>
> It seems to me you're saying that if I wanted the word 'cool' to be blue,
> I could do the following:
>
> 1. PLOT, findgen(20)
>
> 2. Break the title string into 3 strings
>
> 3. Make 3 calls to XYOUTS
>
> So my question is, how would I know the correct positions to send to
> XYOUTS so that the xtitle appears in the same place as it would as if I
> had just called
>
> PLOT, findgen(20), xtitle='this is a cool title'
>
> ???

Uh, oh. I was afraid this wasn't as easy as Ken thought
it would be. :-(

I'd start with !X.Window and !Y.Window as likely places
to figure out where a title goes. Just be sure you like
Charsize=1, or you might *really* get bogged down. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Color Fonts?!?!? [message #30447 is a reply to message #30304] Tue, 23 April 2002 12:45 Go to previous messageGo to next message
Ken Mankoff is currently offline  Ken Mankoff
Messages: 158
Registered: February 2000
Senior Member
On Tue, 23 Apr 2002, Reimar Bauer wrote:
> This is all to complicated
> for example
>
> tek_color
> text=['Dies',' ist',' ein',' Test']
> xyouts,0.5,0.5,text,color=[0,5,2,3,4]
>
> You need as much blanks as letters for each word.
> This could be done by strlen.

Wow, that was easy.

David: It seems this problem is easily solvable no matter how many
times you say "This is a very hard problem" :)

But the "0.5, 0.5" argument to xyouts still needs to be calculated
based upon the current plot, using !x.crange, and !y.crange, and
!y.margin.

-k.
--
------------------------------------------------------------ ---------------
Ken Mankoff http://lasp.colorado.edu/snoe/
http://lasp.colorado.edu/mars/
http://lasp.colorado.edu/~mankoff/ http://lasp.colorado.edu/marsrobot/
------------------------------------------------------------ ---------------
Re : Color Fonts?!?!? [message #31863 is a reply to message #30304] Tue, 20 August 2002 20:13 Go to previous message
rmw092001 is currently offline  rmw092001
Messages: 17
Registered: January 2002
Junior Member
Hello,
I wanted to plot a string with words in different colors, and found
this thread from a few months ago (unfortunately google doesn't allow
to restart old newsgroup threads). But isn't there a much easier way -

loadct,33
a=['the',' quick',' brown',' fox',' jumped',' over',' the',' lazy','
dog']
xyouts,.1,.5,a(0),color=20
for i=1,8 do xyouts,a(i),color=20+i*25

where XYOUTS remembers the last position if you don't give it x,y
values???? Anyway, just posting this so it's archived on google, in
case it's useful

RW
=====
Subject: Re: Color Fonts?!?!?
Date: 2002-04-17 12:20:13 PST

> Date: Wed, 17 Apr 2002 12:26:45 -0600
> From: Sean Davis <sdavis@nis.lanl.gov>
> Does anyone know how to make a string have different colored fonts. I
> would like the x-axis title on a plot to have a string that has different
> colors. thanks!

OK, after re-reading your post, it seems like you really do want each
letter to be a different color in the same string (weird!). In order
to do this via the method I showed in my last post, you need to use
fixed-width fonts OR somehow get plot to accept an "ALIGN=0.0" call.
If you can do either of these, it is simple to adapt the code below to
a loop of PLOT calls, with xtitle= being the key part.

If you want to do it in your normal font, you have to use XYOUTS, and
position the string in the correct location yourself. But here is how
to get a rainbow string:

data = indgen(10)
title = 'This is a Title'
plot, data
for i=15, 0, -1 do $
xyouts, 0.5, 0.5, align=0.0, /norm, $
strmid(title,0,i)+strmid(' ',i,15), $
color=255-(i*12), chars=2

This is getting closer to the "extraordinary hack" that David
mentioned (as in "extraordinary ugly").
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Is there a fast Complex ATAN in IDL 5.5?
Next Topic: From a novice in IDL

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

Current Time: Wed Oct 08 14:32:46 PDT 2025

Total time taken to generate the page: 0.00481 seconds