* Metapost labeling question. Please help
@ 2009-04-03 1:02 Curiouslearn
2009-04-03 5:35 ` Mojca Miklavec
2009-04-03 10:52 ` Peter Rolf
0 siblings, 2 replies; 6+ messages in thread
From: Curiouslearn @ 2009-04-03 1:02 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 716 bytes --]
Hi,
I want the labels as (0.5,0.55,0.6,0.65,0.7,...,1)
or (0.50,0.55,0.60,0.65,0.70,...,1). Either of these two is fine.
I tried the following code for this.
\starttext
\startuseMPgraphic{labeltest}
numeric rmin,rmax;
rmin := 0.5; rmax := 1;
ux := 25cm; uy :=10cm;
% draw axes
draw (rmin,0)*ux -- (rmax+0.1,0)*ux;
draw (rmin,0)*ux -- (rmin*ux,(1.1)*uy);
for x = 0.5 step 0.05 until 1.1:
label.bot(textext(decimal(x)),(x*ux,x*uy));
endfor;
\stopuseMPgraphic
\useMPgraphic{labeltest}
\stoptext
I get (0.5,0.55, 0.6,0.65001,0.70001,0.75002,...,1.00003) instead. I don't
understand why I get more than 2 digits after 0.6. Is there a way to
restrict the number of digits after the decimal point.
Thanks very much.
[-- Attachment #1.2: Type: text/html, Size: 1690 bytes --]
[-- Attachment #2: Type: text/plain, Size: 487 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Metapost labeling question. Please help
2009-04-03 1:02 Metapost labeling question. Please help Curiouslearn
@ 2009-04-03 5:35 ` Mojca Miklavec
2009-04-03 10:52 ` Peter Rolf
1 sibling, 0 replies; 6+ messages in thread
From: Mojca Miklavec @ 2009-04-03 5:35 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Fri, Apr 3, 2009 at 03:02, Curiouslearn wrote:
> Hi,
> I want the labels as (0.5,0.55,0.6,0.65,0.7,...,1)
> or (0.50,0.55,0.60,0.65,0.70,...,1). Either of these two is fine.
> I tried the following code for this.
> \starttext
> \startuseMPgraphic{labeltest}
> numeric rmin,rmax;
> rmin := 0.5; rmax := 1;
> ux := 25cm; uy :=10cm;
> % draw axes
> draw (rmin,0)*ux -- (rmax+0.1,0)*ux;
> draw (rmin,0)*ux -- (rmin*ux,(1.1)*uy);
> for x = 0.5 step 0.05 until 1.1:
> label.bot(textext(decimal(x)),(x*ux,x*uy));
> endfor;
> \stopuseMPgraphic
> \useMPgraphic{labeltest}
> \stoptext
> I get (0.5,0.55, 0.6,0.65001,0.70001,0.75002,...,1.00003) instead. I don't
> understand why I get more than 2 digits after 0.6.
It's because you get exact numbers in the terms what metapost
considers exact (multiples of 2^{-something}). You have exactly the
same problem if you work with floating points with any other
programming language.
> Is there a way to
> restrict the number of digits after the decimal point.
> Thanks very much.
See page 18 of metapost manual (speaking of metapost manual present in
TeX Live):
-----
6.2 Operators
The length operator returns the number of characters in a string.
For substring construction, the ⟨of operator⟩ substring is used like this:
substring ⟨pair expression⟩ of ⟨string primary⟩
substring (2,4) of "abcde" is "cd".
-----
You can use substring (0,4) to truncate the number. 0.5 might need
special treatment, so you either need to concatenate it with 0 at the
end or you need to check the lenght of string before using substring.
Mojca
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Metapost labeling question. Please help
2009-04-03 1:02 Metapost labeling question. Please help Curiouslearn
2009-04-03 5:35 ` Mojca Miklavec
@ 2009-04-03 10:52 ` Peter Rolf
2009-04-03 12:47 ` Curiouslearn
1 sibling, 1 reply; 6+ messages in thread
From: Peter Rolf @ 2009-04-03 10:52 UTC (permalink / raw)
To: mailing list for ConTeXt users
Curiouslearn schrieb:
> Hi,
>
> I want the labels as (0.5,0.55,0.6,0.65,0.7,...,1)
> or (0.50,0.55,0.60,0.65,0.70,...,1). Either of these two is fine.
>
> I tried the following code for this.
>
> \starttext
>
> \startuseMPgraphic{labeltest}
> numeric rmin,rmax;
> rmin := 0.5; rmax := 1;
> ux := 25cm; uy :=10cm;
> % draw axes
> draw (rmin,0)*ux -- (rmax+0.1,0)*ux;
> draw (rmin,0)*ux -- (rmin*ux,(1.1)*uy);
> for x = 0.5 step 0.05 until 1.1:
> label.bot(textext(decimal(x)),(x*ux,x*uy));
you accumulate the rounding error with every step of the loop. try to
avoid such 'low value' steps if possible.
for x = 10 step 1 until 22: % 0.05*20 to get an integer loop index
tx := x/20; % correct value
label.bot(textext(decimal(tx)),(tx*ux,tx*uy));
Best wishes, Peter
> endfor;
> \stopuseMPgraphic
>
> \useMPgraphic{labeltest}
>
> \stoptext
>
> I get (0.5,0.55, 0.6,0.65001,0.70001,0.75002,...,1.00003) instead. I
> don't understand why I get more than 2 digits after 0.6. Is there a
> way to restrict the number of digits after the decimal point.
>
> Thanks very much.
>
>
> ------------------------------------------------------------------------
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive : https://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
--
"Es ist doch ein Trost,
das Geldgier manchmal blöd macht."
- Kottan in "Kottan ermittelt", Folge 9: "Die Einteilung" -
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Metapost labeling question. Please help
2009-04-03 10:52 ` Peter Rolf
@ 2009-04-03 12:47 ` Curiouslearn
2009-04-03 13:35 ` Wolfgang Schuster
0 siblings, 1 reply; 6+ messages in thread
From: Curiouslearn @ 2009-04-03 12:47 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2783 bytes --]
Mojca and Peter, thanks very much for your responses. I used Peter's
solution and it worked beautifully.
Does anyone know how I can change the size of these labels? If I try
textext(\tfa decimal(tx))
that does not work.
On Fri, Apr 3, 2009 at 6:52 AM, Peter Rolf <indiego@gmx.net> wrote:
> Curiouslearn schrieb:
>
>> Hi,
>>
>> I want the labels as (0.5,0.55,0.6,0.65,0.7,...,1) or
>> (0.50,0.55,0.60,0.65,0.70,...,1). Either of these two is fine.
>>
>> I tried the following code for this.
>>
>> \starttext
>>
>> \startuseMPgraphic{labeltest}
>> numeric rmin,rmax;
>> rmin := 0.5; rmax := 1;
>> ux := 25cm; uy :=10cm;
>> % draw axes
>> draw (rmin,0)*ux -- (rmax+0.1,0)*ux;
>> draw (rmin,0)*ux -- (rmin*ux,(1.1)*uy);
>> for x = 0.5 step 0.05 until 1.1:
>> label.bot(textext(decimal(x)),(x*ux,x*uy));
>>
> you accumulate the rounding error with every step of the loop. try to avoid
> such 'low value' steps if possible.
>
> for x = 10 step 1 until 22: % 0.05*20 to get an integer loop index
> tx := x/20; % correct value
> label.bot(textext(decimal(tx)),(tx*ux,tx*uy));
>
>
> Best wishes, Peter
>
> endfor;
>> \stopuseMPgraphic
>>
>> \useMPgraphic{labeltest}
>>
>> \stoptext
>>
>> I get (0.5,0.55, 0.6,0.65001,0.70001,0.75002,...,1.00003) instead. I don't
>> understand why I get more than 2 digits after 0.6. Is there a way to
>> restrict the number of digits after the decimal point.
>> Thanks very much.
>>
>> ------------------------------------------------------------------------
>>
>>
>> ___________________________________________________________________________________
>> If your question is of interest to others as well, please add an entry to
>> the Wiki!
>>
>> maillist : ntg-context@ntg.nl /
>> http://www.ntg.nl/mailman/listinfo/ntg-context
>> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
>> archive : https://foundry.supelec.fr/projects/contextrev/
>> wiki : http://contextgarden.net
>>
>> ___________________________________________________________________________________
>>
>>
>
>
> --
> "Es ist doch ein Trost,
> das Geldgier manchmal blöd macht."
>
> - Kottan in "Kottan ermittelt", Folge 9: "Die Einteilung" -
>
>
>
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive : https://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
>
> ___________________________________________________________________________________
>
[-- Attachment #1.2: Type: text/html, Size: 4323 bytes --]
[-- Attachment #2: Type: text/plain, Size: 487 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Metapost labeling question. Please help
2009-04-03 12:47 ` Curiouslearn
@ 2009-04-03 13:35 ` Wolfgang Schuster
2009-04-03 13:48 ` Curiouslearn
0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2009-04-03 13:35 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 03.04.2009 um 14:47 schrieb Curiouslearn:
> Mojca and Peter, thanks very much for your responses. I used Peter's
> solution and it worked beautifully.
>
> Does anyone know how I can change the size of these labels? If I try
>
> textext(\tfa decimal(tx))
textext("\tfa" & decimal(tx))
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Metapost labeling question. Please help
2009-04-03 13:35 ` Wolfgang Schuster
@ 2009-04-03 13:48 ` Curiouslearn
0 siblings, 0 replies; 6+ messages in thread
From: Curiouslearn @ 2009-04-03 13:48 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 959 bytes --]
Beautiful! Thanks, Wolfgang.
On Fri, Apr 3, 2009 at 9:35 AM, Wolfgang Schuster <
schuster.wolfgang@googlemail.com> wrote:
>
> Am 03.04.2009 um 14:47 schrieb Curiouslearn:
>
> Mojca and Peter, thanks very much for your responses. I used Peter's
>> solution and it worked beautifully.
>>
>> Does anyone know how I can change the size of these labels? If I try
>>
>> textext(\tfa decimal(tx))
>>
>
> textext("\tfa" & decimal(tx))
>
> Wolfgang
>
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive : https://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
>
> ___________________________________________________________________________________
>
[-- Attachment #1.2: Type: text/html, Size: 1857 bytes --]
[-- Attachment #2: Type: text/plain, Size: 487 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-04-03 13:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03 1:02 Metapost labeling question. Please help Curiouslearn
2009-04-03 5:35 ` Mojca Miklavec
2009-04-03 10:52 ` Peter Rolf
2009-04-03 12:47 ` Curiouslearn
2009-04-03 13:35 ` Wolfgang Schuster
2009-04-03 13:48 ` Curiouslearn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).