# How to Plot the Direction Field and Integral Curves Correctly with Plots

**URL:** https://discourse.julialang.org/t/how-to-plot-the-direction-field-and-integral-curves-correctly-with-plots/89184
**Category:** General Usage
**Tags:** question, plotting
**Created:** [October 24, 2022, 7:31am UTC](https://discourse.julialang.org/t/how-to-plot-the-direction-field-and-integral-curves-correctly-with-plots/89184 "2022-10-24T07:31:01Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)
#### Post date: [October 27, 2022, 9:02pm UTC](https://discourse.julialang.org/t/how-to-plot-the-direction-field-and-integral-curves-correctly-with-plots/89184/4 "2022-10-27T21:02:01Z")

</div>

Ah okay, so it looks like you’re plotting the gradient field when you actually want the [slope field](https://en.wikipedia.org/wiki/Slope_field). When you change it out the plots match:

```julia
using Plots
gr()
#gr(size=(600,400))

function example()
  X = range(-2, stop=2, length=50)
  Y = range(-2, stop=2, length=50)
  f(x, y) = -x^3 + 3y - y^3
  contour(X, Y, f)

  x = range(-2, stop=2, length=15)
  y = range(-2, stop=2, length=15)

  dydx_norm(x, y) = [1; x^2/(1 - y^2)] / 25

  quiver!(repeat(x,11), vec(repeat(y',11)), quiver=dydx_norm, c=:blue)

  xlims!(-2, 2)
  ylims!(-2, 2)
    
  # to save as png uncomment the code below and gr(size=(600,400))
  #png("example")
end

example()

```

 ![slope_field](https://global.discourse-cdn.com/julialang/original/3X/2/e/2e12ee89dfd866d38904899a4047d6c9c57f94f2.jpeg)

The default plot options look kind of bad for this plot. I would actually recommend using [Makie.jl](https://docs.makie.org/stable/) for something that looks as good as the Maple/Mathematica version (also not need to manually normalize your plot):

```julia
using CairoMakie

fig = Figure()
ax = Axis(fig[1,1])

X = range(-2, stop=2, length=50)
Y = range(-2, stop=2, length=50)
f(x, y) = -x^3 + 3y - y^3

contour!(X, Y, f, color = :blue, linewidth=2)

dydx(x,y) = Point2f(1, x^2/(1 - y^2))

streamplot!(dydx, -2.0..2.0, -2.0..2.0, colormap=:blues)

fig

```

 ![makie_plot](https://global.discourse-cdn.com/julialang/original/3X/5/c/5c4f805b64039a010d97cac1e965d606a6d8d861.png)

Hope that clears things up!

---

_[View the full topic](https://discourse.julialang.org/t/how-to-plot-the-direction-field-and-integral-curves-correctly-with-plots/89184)._
