# Manipulate does not display the output from a Show correctly [duplicate]

The following code does not display the Plot correctly. Specifically, the Plot axes are not displayed in the output.

Manipulate [max = NMaximize[{price x^0.5 - 0.2 x, x >= 0}, x];
pt = Graphics[{PointSize[.02], Red,
Point[{(x /. max[[2]]), max[[1]]}]}];
plt = Plot[price x^0.5 - 0.2 x, {x, 0, 20}, PlotRange -> All,
Axes -> True, AxesLabel -> "x"];
Show[pt, plt],
{price, 1, 10}]


• Welcome to Mathematica StackExchange! Swap the order: Show[plt, pt] Feb 16, 2022 at 12:54
• MMA uses the options that it encounters first. Therefore by putting pt before plt, the options of pt are used. Alternatively, you may use Axes->True in the Show command Feb 16, 2022 at 14:02
• Show[pt, plt, Axes -> True] Feb 17, 2022 at 3:43

Epilog can be used to include the red point and other Graphics primitives if required.

Clear[price, x];
Manipulate[max = NMaximize[{price x^0.5 - 0.2 x, x >= 0}, x];
maxval = First@max;
xmax = x /. Last@max;
Plot[price x^0.5 - 0.2 x
, {x, 0, 20}
, PlotRange -> {0, 4}
, Axes -> True
, AxesLabel -> "x"
, Epilog -> {AbsolutePointSize[8], Red
, Point[{xmax, maxval}]
, Text[
Style["{" <> ToString@(xmax) <> ", " <> ToString@maxval <> "}",
Black, Bold], {Max[2.5, (xmax) + 0.2], maxval + 0.2}]
, Text[
Style["{Price = " <> ToString@price <> "}", Black, Bold], {3,
3.9}]
, Dashed, Black
, Line[{{xmax, maxval}, {xmax, 0}}]
, Line[{{0, maxval}, {xmax, maxval}}]
}
]
,
{price, 0.2, 1.78}
]

• This is a big improvement on my version, I was not aware of the use of Epilog in Plot.
– BenW
Feb 17, 2022 at 6:14

Try this:

Manipulate[max = NMaximize[{price x^0.5 - 0.2 x, x >= 0}, x];
pt = Graphics[{PointSize[.02], Red,
Point[{(x /. max[[2]]), max[[1]]}]}];
plt = Plot[price x^0.5 - 0.2 x, {x, 0, 20}, PlotRange -> {0, 4},
Axes -> True, AxesLabel -> "x"];
Show[plt, pt], {price, 0.2, 1.78}]


Have fun!

The plot range should depend on the max value.

maxpts[price_?NumericQ] :=
Block[{x}, x /. NMaximize[{price x^0.5 - 0.2 x, x >= 0}, x][[2]]];
Manipulate[
Plot[price x^0.5 - 0.2 x, {x, 0, 2*maxpts@price},
Mesh -> {{maxpts@price}},
MeshStyle -> Directive[AbsolutePointSize[10], Red],
PlotRange -> All, Axes -> True, AxesLabel -> "x"], {price, 1, 10}]