# How to use PyPlot.jl to draw the graph of DifferentialEquations

**URL:** <https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 22, 2021, 1:35pm UTC](https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487 "2021-12-22T13:35:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minghao\_Du](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minghao_du/32/32151_2.png) [@Minghao\_Du](https://discourse.julialang.org/u/Minghao_Du)\
**Post date:** [December 22, 2021, 1:35pm UTC](https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487/1 "2021-12-22T13:35:37Z")

</div>

The sol of the “DifferentialEquations.jl” package can be nicely drawn with Plots, like the following

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/a/5a5091ea2300bb0e75174cefacd5089146c740e2.jpeg)

But if you use the “PyPlot.jl” package, how do you draw the sol curve?

The IDE I use is Pluto

```julia
using DifferentialEquations
import PyPlot as plt

let
	l = 1.0                            
	m = 1.0                           
	g = 9.81                           

	function pendulum!(du,u,p,t)
   		du[1] = u[2]                 
    	du[2] = -3g/(2l)*sin(u[1]) + 3/(m*l^2)*p(t) 
	end

	θ₀ = 0.01                          
	ω₀ = 0.0                          
	u₀ = [θ₀, ω₀]                     
	tspan = (0.0,10.0)                

	M = t->0.1sin(t)                  

	prob = ODEProblem(pendulum!,u₀,tspan,M)
	sol = solve(prob)
	
	plt.clf()
	plt.plot(sol.t, sol[1,:])
	plt.gcf()
end

```

---

<div class="post-metadata">

**Author:** ![Minghao\_Du](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minghao_du/32/32151_2.png) [@Minghao\_Du](https://discourse.julialang.org/u/Minghao_Du)\
**Post date:** [December 22, 2021, 1:36pm UTC](https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487/2 "2021-12-22T13:36:17Z")

</div>

This is the image I drew with PyPlot.jl and it is not a curve

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/f/5fced79ff3aa254b0dbac72380c1da2560830048.png)

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [December 22, 2021, 2:05pm UTC](https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487/3 "2021-12-22T14:05:47Z")

</div>

`sol.t` has adaptive time steps. The solution object is callable so you can use a range for time steps and call solution object with that range. [This](https://diffeq.sciml.ai/stable/basics/plot/#Plotting-Without-the-Plot-Recipe) explains manual plotting.

---

<div class="post-metadata">

**Author:** ![Minghao\_Du](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minghao_du/32/32151_2.png) [@Minghao\_Du](https://discourse.julialang.org/u/Minghao_Du)\
**Post date:** [December 22, 2021, 2:59pm UTC](https://discourse.julialang.org/t/how-to-use-pyplot-jl-to-draw-the-graph-of-differentialequations/73487/4 "2021-12-22T14:59:13Z")

</div>

Thanks!
