2
$\begingroup$

This question already has an answer here:

I enter this:

sol17 = DSolveValue[{y'[x] == 2 - y[x], y[0] == 3}, y[x], x];
p1sol17 = Plot[sol17, {x, -3, 3},
  Epilog -> {Red, PointSize[Large], Point[{0, 3}],
    Text[Style["(0,3)", 10, Black, Background -> White], {0, 
      3}, {-2, -2}]}]

And I get the following image: enter image description here

I do this:

sol17 = DSolveValue[{y'[x] == 2 - y[x], y[0] == 1}, y[x], x];
p2sol17 = Plot[sol17, {x, -3, 3},
  Epilog -> {Red, PointSize[Large], Point[{0, 1}],
    Text[Style["(0,1)", 10, Black, Background -> White], {0, 1}, {-2, 
      2}]}]

And I get the following image: enter image description here

Now I try to combine them with the Show command:

Show[{p1sol17, p2sol17}, PlotRange -> {{-3, 3}, {-10, 10}}]

And I get this image: enter image description here

Note how the bottom curve is incorrect? What is going on here?

Mathematica 10.0.2 on MacBook Pro using Yosemite.

$\endgroup$

marked as duplicate by Michael E2 differential-equations Dec 28 '16 at 0:09

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.

2
$\begingroup$

It's not actually that the bottom plot is incorrect, it's that the horizontal axis is not drawn where you expect it. Consider this simplification, where it is more clear that the position of the horizontal axes are placed differently. Since Show inherits many of the plotting features from the first argument, the order of the plots matters in the placement of the axes.

sol17 = DSolveValue[{y'[x] == 2 - y[x], y[0] == 3}, y[x], x];
sol27 = DSolveValue[{y'[x] == 2 - y[x], y[0] == 1}, y[x], x];
Show[{Plot[sol27, {x, -3, 3}], Plot[sol17, {x, -3, 3}]}, 
 PlotRange -> {-1, 3}]
Show[{Plot[sol17, {x, -3, 3}], Plot[sol27, {x, -3, 3}]}, 
 PlotRange -> {-1, 3}]

enter image description here

enter image description here

$\endgroup$
  • $\begingroup$ Also, the second dot disappears because Epilog is a graphics option. Show concatenates the options, and only the first is applied (e.g. try Plot[x^2,{x,-1,1},PlotStyle->Red,PlotStyle->Green]). $\endgroup$ – 2012rcampion Jan 24 '15 at 20:51
  • $\begingroup$ Great catch, on looking at the original curve it is clear that the x axis was drawn at y=1. $\endgroup$ – March Ho Jan 24 '15 at 21:22
2
$\begingroup$

Thanks for the help. I came up with two solutions that worked.

Show[p1sol17, p2sol17,
 Graphics[{Red, PointSize[Large], Point[{{0, 3}, {0, 1}}],
   Black,
   Text["(0,3)", {0, 3}, {-2, -2}],
   Text["(0,1)", {0, 1}, {-2, 2}]}],
 AxesOrigin -> {0, 0},
 AxesLabel -> {x, y},
 PlotRange -> {{-3, 3}, {-10, 10}}
 ]

Which produced the correct image.

enter image description here

And a second approach:

sol = Table[
   DSolveValue[{y'[x] == 2 - y[x], y[0] == b}, y[x], 
    x], {b, {1, 3}}];
Plot[sol, {x, -3, 3},
 Epilog -> {
   Red, PointSize[Large], Point[{{0, 3}, {0, 1}}],
   Black,
   Text["(0,3)", {0, 3}, {-2, -2}],
   Text["(0,1)", {0, 1}, {-2, 2}]
   },
 AxesOrigin -> {0, 0},
 AxesLabel -> {x, y},
 PlotRange -> {{-3, 3}, {-10, 10}}]

Which produced this image:

enter image description here

So, you can see that your help was successful!

$\endgroup$

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