Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.
share|improve this question

migrated from stackoverflow.com Apr 22 '12 at 13:47

This question came from our site for professional and enthusiast programmers.

    
What do you mean by manually?? –  belisarius Apr 21 '12 at 5:51
    
Related questions that address the issue of drawing stream line curves are "Sketching solution curves for differential equations" and "I'd like to display field lines for a point charge in 3 dimensions" –  Jens Apr 22 '12 at 16:09

3 Answers 3

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

share|improve this answer
    
Oi my! I did not understand what he meant by plotted the curves manually. ! :) –  belisarius Apr 22 '12 at 1:28
    
@belisarius I'm just guessing here. I don't know for sure if that's what the OP meant. –  Heike Apr 22 '12 at 15:18

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.

share|improve this answer
    
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. –  Heike Apr 30 '12 at 6:54

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.