# Specify the admissible region of SIS model when plotting its phase portrait, using streamplot

**URL:** <https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [September 4, 2021, 11:48am UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688 "2021-09-04T11:48:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goh/32/28770_2.png) [@GoH](https://discourse.julialang.org/u/GoH)\
**Post date:** [September 4, 2021, 11:48am UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688/1 "2021-09-04T11:48:59Z")

</div>

Hi I am trying to visualize the phase space of SIS model, but here is what I obtained. The problem is the trajectories should on the line of S+I=1, but somehow they did not, in the plot.

 ![Screen Shot 2021-09-04 at 13.48.17](https://global.discourse-cdn.com/julialang/original/3X/3/f/3f51d0a1f3c66fee803e1826b4b246b1e6b270d0.png)  
here is my code

```julia
begin
	using CairoMakie
	let
		β=0.8
		μ=0.1
	    PP_SIS(S,I) = Point(-β*S*I+μ*I,β*S*I-μ*I)
	    fig = Figure(resolution = (1400, 800), fontsize = 20)
	    ax1 = fig[1, 1] = Axis(fig, xlabel = "S", ylabel = "I", title = "phase portrait of SIS model", aspect = 1, backgroundcolor = :black)
	    
	    streamplot!(ax1, PP_SIS, 0.01..0.99, 0.01..0.99, colormap = Reverse(:plasma),
	        gridsize= (20,20), arrow_size = 20)
	    
		    fig
	end
end

```

Thus, im wondering how to specify the admissible region (S+I=1) of SIS model when plotting its phase portrait, using streamplot? Hope anyone could help. Thank you!

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [September 4, 2021, 12:53pm UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688/2 "2021-09-04T12:53:08Z")

</div>

> [@GoH](#):
>
> The problem is the trajectories should on the line of S+I=1,

What do you mean precisely with that? Physically, the model conserves S+I=1, so yes, actually evolving the model with initial conditions that satisfy S+I = 1 would keep it on this manifold. But that’s not what `streamplot` does. it just plots the vector field.

You can’t use `streamplot` for what you want. I propose to use a `quiver` plot. Calculate the rate of change in all points that satisfy `S+I=1` and just plot a quiver of arrows on these points.

---

<div class="post-metadata">

**Author:** ![GoH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goh/32/28770_2.png) [@GoH](https://discourse.julialang.org/u/GoH)\
**Post date:** [September 4, 2021, 1:15pm UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688/3 "2021-09-04T13:15:26Z")

</div>

> What do you mean precisely with that? Physically, the model conserves S+I=1, so yes, actually evolving the model with initial conditions that satisfy S+I = 1 would keep it on this manifold. But that’s not what `streamplot` does. it just plots the vector field.

I think the trajectories supposed to strictly on the line of S+I=1, and the phase portrait of SIS model is like this:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/f/2fd4f1c4337c91602a9bbd12accfb9b797f7529c.png)

> You can’t use `streamplot` for what you want.

I initially found the solution in the post [Plotting a phase portrait of a differential equation](https://discourse.julialang.org/t/plotting-a-phase-portrait-of-a-differential-equation/29208) is streamplot, so I use it. am I misunderstanding?

Also, I am not sure whether the following understanding is correct:

**Plotting the vector field** : plot the vector on each point, its direction is obtained according to the differential equations (\frac{dS}{dt},\frac{dI}{dt},\frac{dR}{dt}). So, we can use `streamplot`.

**Plotting the phase space**  
plot trajectories starting from every possible initial  
state (initial condition). And, your suggestion is `quiver` plot?

Thanks!

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [September 4, 2021, 1:24pm UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688/4 "2021-09-04T13:24:41Z")

</div>

As I said, the stream plot does not make what you want. The plot you paste in your latest comment can’t be done with the streamplot given intervals. Obviously, if you do `streamplot(f, interval1, interval2)`, it will evaluate arrows over all points in the given box, not just those that lie on the line S+I=1.

So, just create a vector of points `points = [Point2f0(x, 1-x) for x in 0:0.1:1]`, then calculate their velocities `v = [f(x) for x in points]` and then do a `quiver(points, v)`.

---

<div class="post-metadata">

**Author:** ![GoH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goh/32/28770_2.png) [@GoH](https://discourse.julialang.org/u/GoH)\
**Post date:** [September 4, 2021, 2:43pm UTC](https://discourse.julialang.org/t/specify-the-admissible-region-of-sis-model-when-plotting-its-phase-portrait-using-streamplot/67688/5 "2021-09-04T14:43:05Z")

</div>

This solves my question. Thank you!
