2
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by Michael E2 plotting Dec 28 '16 at 0:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ post your code (not a picture only) $\endgroup$ – molekyla777 Sep 19 '14 at 11:35
  • $\begingroup$ ok, I just added the code. $\endgroup$ – Onizuka Sep 19 '14 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 '14 at 11:48
  • $\begingroup$ Adding it in Show or where? $\endgroup$ – Onizuka Sep 19 '14 at 12:03
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$
  • $\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 '14 at 12:59
  • $\begingroup$ @MichaelE2 Yup. That was Yves' comment at the question $\endgroup$ – Dr. belisarius Sep 19 '14 at 13:03
  • $\begingroup$ I didn't notice. Your answer was just that compelling. :) (+1, btw) $\endgroup$ – Michael E2 Sep 19 '14 at 13:07

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