# How to make a function plot dynamic in a combined graphics?

Here is the code:

Dynamic@Show[{Graphics[{LightGray, Rectangle[{0, -1}, {Pi, 1}]}],
Plot[Sin[a x], {x, 0, Pi}]}]
Slider[Dynamic[a]]


The Slider controls the value of a in Plot[] to produce a dynamic plot of Sin[]. I would like to make the Plot[] dynamic only, but it didn't work if i only wrapped plot[] with dynamic[], so i added dynamic to the whole show[]. So how to dynamically update plot[] solely?

• Manipulate[Plot[Sin[a x], {x, 0, π}, PlotRange -> {{0, π}, {-1, 1}}, Prolog -> {LightGray, Rectangle[{0, -1}, {π, 1}]}], {{a, 1}, -2, 2, 0.01, Appearance -> "Labeled"}] – Bob Hanlon Sep 19 '20 at 4:46
• the code i posted in the question is a simplified example, the original code has combined graphics and plot, so it's unlikely to modify it by using Prolog. – DORA Sep 19 '20 at 4:59
• Besides, the Prolog will be updated as well while the value of a changes, right? Because the whole Plot is dynamic. – DORA Sep 19 '20 at 5:06
• Slider[Dynamic[a]] gr = Graphics[{LightGray, Rectangle[{0, -1}, {Pi, 1}]}]; Dynamic[Show[gr, Plot[Sin[a x], {x, 0, Pi}]]] – Bob Hanlon Sep 19 '20 at 5:24

## 1 Answer

You can evaluate the Graphics expression in place, so that it just becomes a constant in the Show expression. Like so: 