Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I want a plot label that shows interactively the values of a

736 views
Skip to first unread message

Massimiliano LANDI

unread,
Aug 13, 2011, 6:50:29 AM8/13/11
to
Hello everyone

I am trying to add to a plot I created a text that shows the value of a variable, call it p2, that can be changed via Manipulate.

So I did:

Manipulate[
Plot[....,Epilog->{Text[Style["p2=" p2, 18, If[(A/(1 + B n) <= p2 <= (A + A n)/(1 + n + B n) && k == 2) || (p2 == 1 && k == 1), Red, Black], Background -> LightGray]}],
...]

The funny thing is that with this code, in the text label, the actual value of the variable appears before the text p2.

For example, when I set p2=10, the label in the graph becomes

10 p2

whereas I would like to see

p2 = 10

Any help?

Thanks in advance

Massimiliano Landi

Heike Gramberg

unread,
Aug 14, 2011, 8:10:56 AM8/14/11
to
Mathematica interprets the expression "p2=" p2 as a multiplication. To
get what you want you could use
Row[{"p2=", p2}] instead.

Heike.

Chris Degnen

unread,
Aug 14, 2011, 8:16:07 AM8/14/11
to
You could try something like this,
adapted from the help examples on Manipulate and Epilog:-

Manipulate[
Plot[Sin[x(1+p2*x)],{x,0,6},
Epilog->{Inset[
Text[Style["p2="<>ToString[p2],20,If[p2<1,Red,Black]],
Background->LightGray],{Right,Top},{Right,Top}]}],{p2,0,2}]

Yves Klett

unread,
Aug 14, 2011, 8:21:51 AM8/14/11
to
Use StringJoin and ToString to produce a string that is displayed
properly. Otherwise, you get a mix of strings and expressions that is
ordered like any other input:

"p2="*10

becomes

10 "p2="

Regards,
Yves

PS: Supplying incomplete code (with ... etc.) is not very helpful. Paste
working code if possible or make up a simplified - also working - example.

Am 13.08.2011 12:50, schrieb Massimiliano LANDI:
> Hello everyone
>
> I am trying to add to a plot I created a text that shows the value of a variable, call it p2, that can be changed via Manipulate.
>
> So I did:
>
> Manipulate[
> Plot[....,Epilog->{Text[Style["p2=" p2, 18, If[(A/(1 + B n) <= p2 <= (A + A n)/(1 + n + B n) && k == 2) || (p2 == 1 && k == 1), Red, Black], Background -> LightGray]}],

> ....]

Massimiliano LANDI

unread,
Aug 14, 2011, 8:24:26 AM8/14/11
to
Thanks a lot Heike.

Problem solved.

Massimiliano Landi
________________________________________
From: Heike Gramberg [heike.g...@gmail.com]
Sent: Saturday, August 13, 2011 7:09 PM
To: Massimiliano LANDI
Cc: math...@smc.vnet.net
Subject: Re: I want a plot label that shows interactively the values of a

Mathematica interprets the expression "p2=" p2 as a multiplication. To get what you want you could use

Row[{"p2==", p2}] instead.

Heike.

On 13 Aug 2011, at 12:47, Massimiliano LANDI wrote:

> Hello everyone
>
> I am trying to add to a plot I created a text that shows the value of a variable, call it p2, that can be changed via Manipulate.
>
> So I did:
>
> Manipulate[

> Plot[....,Epilog->{Text[Style["p2=" p2, 18, If[(A/(1 + B n) <= p2 <==

0 new messages