Message Boards Message Boards

0
|
1816 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Updating PlotLabels when using Manipulate for multiple plots

Hello -- I have several examples of trying to show the change of some parameter on the shape of a function. I am plotting the "base" function (i.e., Sin[x]) and using the Manipulate function to show the changes of the function: a Sin[k x + phi]. The issue comes when I use the Manipulate function to superimpose the two functions. I would like the PlotLabel of the function being manipulated to update in real time. I'm running into the following issue:

Manipulate[
 Plot[{Sin[x], a Sin[k x + phi]}, {x, 0, 2 Pi}, 
  PlotLabels -> Placed[Automatic, Above ]],
 {k, .1, 4}, {a, 1, 2}, {phi, 0, 2 Pi}
 ]

And here is the output. As you can see, the label for the "static" function is showing up fine... but the label for the function that is being manipulated is garbled.

Any suggestions would be welcome!

enter image description here

POSTED BY: Gaurav Khanna
3 Replies

Rohit -- I actually think what did the trick was the Evaluate function. You can see the actual expressions even if you remove the LocalizeVariables -> False condition.

POSTED BY: Gaurav Khanna
Posted 2 years ago

Hi Gaurav,

Manipulate scopes local variables by default. To avoid that, add the option LocalizeVariables -> False.

enter image description here

To show the actual values of k, a, phi

Manipulate[
 Plot[{Sin[x], Evaluate[a Sin[k x + phi]]}
  , {x, 0, 2 Pi}
  , PlotLabels -> Placed["Expressions", Above]]
 , {k, .1, 4}, {a, 1, 2}, {phi, 0, 2 Pi}
 , LocalizeVariables -> False]

enter image description here

POSTED BY: Rohit Namjoshi

Rohit -- thanks for your response and that seemed to work!

POSTED BY: Gaurav Khanna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract