2
$\begingroup$

I am facing an issue when trying to use Show command to show multiple graphs within one graph. Show command only shows red dot from one of the graph.

u3b = Plot[f1[a, x], {x, -10, 20}, PlotStyle -> Blue, 
  AxesLabel -> {"x", "y"}, 
  Epilog -> {PointSize[Large], Red, 
    Point[{x, 0} /. NSolve[f1[a, x]]]}]

first graph with red dot

dydx = D[x^3 - a x^2 - x + 1, x];

Plot[dydx, {x, -10, 20}, PlotStyle -> Blue, AxesLabel -> {"x", "y"}]
u3c = Plot[dydx, {x, -10, 20}, PlotRange -> Automatic, 
  PlotStyle -> Blue, AxesLabel -> {"x", "y"}, 
  Epilog -> {PointSize[Large], Red, Point[{x, 0} /. NSolve[dydx]]}]

Show[u3b, u3c, PlotRange -> Automatic]

second graph with red dot and Show command that left the red dot out

$\endgroup$
4
  • 1
    $\begingroup$ post your code (not a picture only) $\endgroup$ Sep 19, 2014 at 11:35
  • $\begingroup$ ok, I just added the code. $\endgroup$
    – Onizuka
    Sep 19, 2014 at 11:39
  • 3
    $\begingroup$ Show will use the options of the first argument and thus drop the second occurence of Epilog. You need to add those graphics primitives once more. $\endgroup$
    – Yves Klett
    Sep 19, 2014 at 11:48
  • $\begingroup$ Adding it in Show or where? $\endgroup$
    – Onizuka
    Sep 19, 2014 at 12:03

1 Answer 1

3
$\begingroup$

For example:

f1[a_, x_] := x^3 - a x^2 - x + 1
a = 4;
epilog1 = {PointSize[Large], Red, Point[{x, 0} /. NSolve[f1[a, x]]]};
epilog2 = {PointSize[Large], Green, Point[{x, 0} /. NSolve[D[f1[a, x], x]]]};

u3b = Plot[f1[a, x], {x, -10, 20}, AxesLabel -> {"x", "y"}];
u3c = Plot[D[f1[a, t], t] /. t -> x, {x, -10, 20}];

Show[u3b, u3c, Epilog -> Join[epilog1, epilog2]]

Mathematica graphics

There are in fact a lot of ways to achieve the same result. Another example is:

Show[u3b, u3c, Graphics@Join[epilog1, epilog2]]

The most common problem is that Show[] takes its plot range from the first argument, so you need to be careful about setting it right.

$\endgroup$
3
  • $\begingroup$ One might further point out a common problem with Show is that the graphics options in the first argument override options in subsequent arguments. In this case, that means that the second Epilog is ignored. $\endgroup$
    – Michael E2
    Sep 19, 2014 at 12:59
  • $\begingroup$ @MichaelE2 Yup. That was Yves' comment at the question $\endgroup$ Sep 19, 2014 at 13:03
  • $\begingroup$ I didn't notice. Your answer was just that compelling. :) (+1, btw) $\endgroup$
    – Michael E2
    Sep 19, 2014 at 13:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.