MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Inserting a position-limited Locator inside a Manipulate multiplot

  • To: mathgroup at
  • Subject: [mg107245] Re: [mg107147] Inserting a position-limited Locator inside a Manipulate multiplot
  • From: "David Park" <djmpark at>
  • Date: Sat, 6 Feb 2010 03:26:26 -0500 (EST)
  • References: <19297865.1265285420221.JavaMail.root@n11>

For those who have Presentations, here is a custom dynamic presentation
1) Allow each curve to be individually displayed.
2) Controls the a parameter with a Slider or with an InputField.
3) Constrains two red point locators to the two curves.
4) Displays the current values of the two fields.
5) Allows the center of the plot to be set with a green point locator and
the width of the plot to be set with an InputField and uses a Button to do
the resetting.


 {pt1 = {-1, 0}, pt2 = {1, 0}, a = 1, drawf = True, drawg = True,
  provisionalCenter = {0, 0}, provisionalWidth = 10,
  f, g, center, width,
  calcf, calcg},
 f[x_, a_] := Sin[3 a x] + x;
 g[x_, a_] := Cos[a x];
 calcf[p_, a_] := (pt1 = {First[p], f[First[p], a]};);
 calcg[p_, a_] := (pt2 = {First[p], g[First[p], a]};);
 (* Initialize *)
 calcf[pt1, a]; calcg[pt2, a];
 center = provisionalCenter; width = provisionalWidth;
   (* Checkboxes *)
   phrase["Draw f: ", Checkbox[Dynamic[drawf]], Spacer[10], 
    "Draw g: ", Checkbox[Dynamic[drawg]]],
   (* a parameter *)
   phrase["Parameter a: ", 
    Slider[Dynamic[a, (a = #; calcf[pt1, a]; calcg[pt2, a]) &], {-4, 
     ImageSize -> Small],
    InputField[Dynamic[a, (a = #; calcf[pt1, a]; calcg[pt2, a]) &], 
     ImageSize -> {50, 20}]],
   (* Set PlotRange *)
    Button["Set PlotRange", center = provisionalCenter; 
     width = provisionalWidth;,
     ImageSize -> Medium],
    "Width: ", 
    InputField[Dynamic[provisionalWidth], ImageSize -> {70, 20}]],
   (* Show f and g values *)
     "f: ", ProportionalNumberForm[f[First[pt1], a], {6, 3}],
     "g: ", ProportionalNumberForm[g[First[pt2], a], {6, 3}]],
   (* Curves with locators *)
          f[x, a], {x, First[center] - width/2, 
           First[center] + width/2}],
         Locator[Dynamic[pt1, (pt1 = #; calcf[pt1, a]) &], 
          CirclePointLocator[3, Red]]}, {}],
          g[x, a], {x, First[center] - width/2, 
           First[center] + width/2}],
         Locator[Dynamic[pt2, (pt2 = #; calcg[pt2, a]) &], 
          CirclePointLocator[3, Red]]}, {}]},
     Locator[Dynamic[provisionalCenter], CirclePointLocator[3, Green]]
    Frame -> True,
    PlotRange -> 
     Dynamic@{First[center] + {-width/2, width/2}, 
       Last[center] + {-width/2, width/2}},
    ImageSize -> 400] (* Draw2D *)
   ](* pagelet *),
  Style["Custom Dynamic Presentation", 16]
  ](* panelpage *)

David Park
djmpark at  

From: adrian skaai [mailto:skaai at] 


First of all, i apologize if the question i post has been posted
before... I tried to find an applicable message but could not. of
course my own lack of experience in anything but basic mathematica
functions doesn't help.

My original reason for this project was that i am learning to graph the
behavior of acid-base reactions in human blood. To do this, we are
given titration plots where we plot a solution with only a strong acid
and another one with a strong acid and a weak acid. To those of you not
familiar with such plots, they are useful in determining the ion
difference (or equivalence point) for a solution, which can tell you
much about its acid dissociation constant and other important traits.
If I am successful in implementing this, i would move on to Log-Log
plots of similar behavior, but that would not be much harder if i solve
this problem.

=========The Problem=========

The plot i wanted to make in Mathematica 7 was where i could compare
both behaviors on the same graph (titration plots), so I began by
creating a basic Manipulate Sin(x) plot just to get an idea of the
concept as once i get that, plugging in my functions should be child's
play. There are 3 things i want in the final product:

1. both plots should be modifiable (which i can do)
2. the main plot can persist, but additional ones (some graphs will
have up to 4 plots) should be able to be removed with a checkbox (i did
this with a bit of success)
3. each plot should have a locator that is constrained to follow the
plot and return the values for the plot (this was the kicker for me)

of the three goals, i was able to do #1 & #2 two plots, though i'm not
sure if i can generalize to three or four plots as i want. The hardest
for me has been to integrage locators into the plots, but this is also
the most important. why? because many times the interesting behavior of
these plots is in areas that are hard to read. I have made Manipulate
plots before that zoom in, so that helps, but perhaps im still in love
with the old TI 89 ability to trace a plot (sorry).

anyways, here is one attempt i made:
(*this plot was my first successful combination of two functions. i
want to keep my functions malleable so that i can play with them or
modify them as i need. i now need to insert a locator that will trace
them*) f[a_, x_] := Plot[{Sin[3 a x] + x}, {x, -5, 7}]; g[a_, x_, b_]
:= Plot[Cos[a x] b, {x, -5, 7}]; DynamicModule[{x = x},
Manipulate[Show[{f[a, x], g[a, x, b]}], {a, -4, 4}, {b, {0, 1}, ControlType

=======Extra Info==========

I tried many times to insert a locator, but failed, the following are
two examples of my failed attempts:
(*I had made a few attempts at sticking a LocatorPane in the equations
but sticking it inside a DynamicModule and sticking everything else
in it failed, sticking it inside Manipulate failed, part of the
failure was the fact my Locator required an argument from the
function, but there is no clear way to give it an argument, so im
going to begin from scratch on inventing a single function where i
can stick a locator and get its info on position and also limit its
movement*)Manipulate[Plot[Sin[x], {x, -2 , 2 }], {{p, {0, 0}},

this second attempt was where i was able to update its position... i
think in an earlier attempt it actually worked, but didn't now that i
tried to move it again:
(*this was my first successful integration of the Locator in a plot
along with updating the position of the locator via the PlotLabel.
its not the best solution because you usually want a title for the
plot label, but this is a start*)DynamicModule[{p = {2, 1}}, 
Manipulate[Plot[{2 Sin[x]}, {x, -2 , 2 }, PlotLabel -> Dynamic[p],
 Epilog -> Locator[Dynamic[p, (p = Normalize[#]) &]]]]]

sorry for so much info, but i thought it might help outline my
limitations. I would truly appreciate any help in this issue...
particularly with #3

adrian skaai
email: skaai at
I always welcome email at my address if you are a friend and not a
spammer. With that in mind, the first time you email me, you will be
met by my spam filter. Don't let it put you off, a quick response to my
spam filter will get your message through!

  • Prev by Date: Using matrix-form matrices and vectors in function definitions;
  • Next by Date: Re: Re: What does & mean?
  • Previous by thread: Re: Inserting a position-limited Locator inside a Manipulate multiplot
  • Next by thread: is it a bug?!please help.