Re: Mouse operation, slider, dynamics, plot combination
- To: mathgroup at smc.vnet.net
- Subject: [mg84901] Re: Mouse operation, slider, dynamics, plot combination
- From: Albert Retey <awnl at arcor.net>
- Date: Fri, 18 Jan 2008 05:51:56 -0500 (EST)
- References: <fmmknh$f1e$1@smc.vnet.net>
Hi,
> I am not sure what I am doing wrong here. I am doing the following:
>
> Dynamic[Plot[Sin[x], {x, -r, r},
> PlotRange -> {{-r, r}, {-s, s}},
> Frame -> True,
> ImageSize -> 300,
> FrameLabel -> {Slider[Dynamic[r], {1, 10}], VerticalSlider[Dynamic[s],
> {1, 10}]},
> RotateLabel -> False]
> ]
>
> The above works to some extent, but when I press the mouse on the slider to
> move it, it does not really move well. When I click on a different position
> on the slider, it jumps there and the plot is updated.
>
> One way to fix this problem is to add ContinuousAction -> False to each
> Dynamics, so now the slides move smooth, but the plot is NOT updated until
> one releases the mouse:
>
> Dynamic[Plot[Sin[x], {x, -r, r},
> PlotRange -> {{-r, r}, {-s, s}},
> Frame -> True, ImageSize -> 300,
> FrameLabel -> {Slider[Dynamic[r], {1, 10}, ContinuousAction -> False],
> VerticalSlider[Dynamic[s], {1, 10},
> ContinuousAction -> False]},
> RotateLabel -> False]
> ]
>
> I'd like the slider to move smoothly and the put updated at the same time. I
> am sure this can be done ofcourse.
>
> I tried adding Refersh, but this did not help. I tried playing with the
> options to Dynamic[ Plot[..], {options} ] but again, did not get it working.
I think your problem is that you recreate the whole plot whenever you
change one of your parameters. Note that you only need to make the
option values Dynamic. Also I think it is not possible to use the
Sliders as FrameLabels without problems. The following does what I think
you intend to do and runs smoothly on my machine:
Grid[{
{
VerticalSlider[Dynamic[s], {1, 10}],
Show[
Plot[Sin[x], {x, -10, 10}, Frame -> True, ImageSize -> 300],
PlotRange -> Dynamic[{{-r, r}, {-s, s}}]
]
}, {
"", Slider[Dynamic[r], {1, 10}, ImageSize -> 300]}
}]
You might want to localize r and s with DynamicModule:
DynamicModule[{s = 5.5, r = 5.5},
Grid[{
{
VerticalSlider[Dynamic[s], {1, 10}],
Show[
Plot[Sin[x], {x, -10, 10}],
PlotRange -> Dynamic[{{-r, r}, {-s, s}}],
Frame -> True, ImageSize -> 300
}, {
"", Slider[Dynamic[r], {1, 10}, ImageSize -> 300]}
}]
]
hth, albert