1
$\begingroup$

I would like to make a slope field. Here is the code

slopefield = 
 VectorPlot[{1, .005 * p*(10 - p) }, {t, -1.5, 20}, {p, -10, 16}, 
  Ticks -> None, AxesLabel -> {t, p},  Axes -> True, 
  VectorScale -> {Tiny, Automatic, None}, VectorPoints -> 15]

I solved the differential equations and plotted the curves manually. Three questions:

  1. Is there an easier way to do it?
  2. Ticks -> None doesn't seems to work. I still get labels for the tick marks.
  3. I'd like to selectively label 2 tick marks.
$\endgroup$
3
$\begingroup$

I'm assuming here that the curves you mentioned are streamlines of the vector field. You can plot those automatically without having to solve any differential equations by using the options StreamPoints, for example to plot the stream lines going through the points

points =  Transpose@ArrayPad[{Range[-10, 16, 2]}, {{1, 0}, {0, 0}}]

(* ==> {{0, -10}, {0, -8}, {0, -6}, {0, -4}, {0, -2}, {0, 0}, {0, 2}, {0, 4}, 
        {0, 6}, {0, 8}, {0, 10}, {0, 12}, {0, 14}, {0, 16}} *)

you can do

slopefield = 
 VectorPlot[{1, .005*p*(10 - p)}, {t, -1.5, 20}, {p, -10, 16}, 
  FrameTicks -> None, AxesLabel -> {t, p}, Axes -> True, 
  VectorScale -> {Tiny, Automatic, None}, VectorPoints -> 15, 
  StreamPoints -> points,
  StreamStyle -> {Red, "Line"}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Oi my! I did not understand what he meant by plotted the curves manually. ! :) $\endgroup$ – Dr. belisarius Apr 22 '12 at 1:28
  • $\begingroup$ @belisarius I'm just guessing here. I don't know for sure if that's what the OP meant. $\endgroup$ – Heike Apr 22 '12 at 15:18
3
$\begingroup$

To plot the vector field and the streamlines (curves) together, there are two other plot functions that are specialized for this purpose:

The difference to VectorPlot is that Mathematica can automatically pick a set of curves for you. You can specify the starting points for the curves, but you don't have to:

StreamPlot[{1, .005*p*(10 - p)}, {t, -1.5, 20}, {p, -10, 16}, 
 AxesLabel -> {t, p}, Axes -> True, 
 VectorScale -> {Tiny, Automatic, None}, VectorPoints -> 15,
 StreamStyle -> Red, FrameTicks -> {{5, 10}, {-10, 10}, {}, {}}]

StremPlot

Here, I've also added a FrameTicks specification that labels several special points on the horizontal and vertical axes.

The other alternative, which contains some additional visual information, is this:

LineIntegralConvolutionPlot[{1, .005*p*(10 - p)}, {t, -1.5, 
  20}, {p, -10, 16}, Ticks -> None, AxesLabel -> {t, p}, Axes -> True,
  VectorScale -> {Tiny, Automatic, None}, VectorPoints -> 15, 
 VectorStyle -> LightGray, ColorFunction -> ColorData["Rainbow"], 
 FrameTicks -> {{5, 10}, {-10, 10}, {}, {}}, Background -> Black, 
 BaseStyle -> White, FrameTicksStyle -> Yellow, ImageMargins -> 5]

convolution plot

The last plot can be customized by adding the actual streamlines with the StreamPoints option (see the documentation), but the colored background serves the same purpose. The idea is that the background pattern is physically like the pattern you'd get (e.g.) from grass seeds in an electric field, or irons filings in a magnetic field, etc. And of course the color encodes information about the field strength.

$\endgroup$
  • $\begingroup$ Actually, You don't need to explicitly specify the starting points for the streamlines in VectorPlot. You can also do something like StreamPoints -> 16 which will plot 16 strategically placed streamlines. $\endgroup$ – Heike Apr 30 '12 at 6:54
2
$\begingroup$

For example:

VectorPlot[{1, .005*p*(10 - p)}, {t, -1.5, 20}, {p, -10, 16}, 
          FrameTicks -> {
              Join[{{0, "ZERO", {0, .1}, Red}}, Table[{i, ""}, {i, -1.5, 20, 3}]], 
                                                Table[{i, ""}, {i, -10, 16, 3}]}, 
          AxesLabel -> {t, p}, 
          Frame     -> True, 
          VectorScale -> {Tiny, Automatic, None}, 
          VectorPoints -> 15]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy