# How to generate graph?

**URL:** <https://discourse.julialang.org/t/how-to-generate-graph/14911>\
**Category:** Optimization (Mathematical)\
**Tags:** plotting\
**Created:** [September 13, 2018, 2:39pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911 "2018-09-13T14:39:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [September 13, 2018, 2:39pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/1 "2018-09-13T14:39:46Z")

</div>

How to generate graph of a mathematical model?

I’ve already tried using PyPlot, and I still could not.

```julia
using JuMP, Cbc

m = Model(solver = CbcSolver())

#Declaração das variáveis
@defVar(m, x1 >= 0)
@defVar(m, x2 >= 0)

#Função Objetivo
@setObjective(m, Max, 3x1 + 5x2)

#Restrições
@addConstraint(m, 1x1 + 0x2 <= 4)
@addConstraint(m, 0x1 + 2x2 <= 12)
@addConstraint(m, 3x1 + 2x2 <= 18)

#Leitura do modelo
print(m)

#Resolução e visualização dos resultados
status = solve(m) # solves the model
println("Objective value: ", getObjectiveValue(m))
println("x1 = ", getValue(x1))
println("x2 = ", getValue(x2))

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 13, 2018, 3:37pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/2 "2018-09-13T15:37:07Z")

</div>

What exactly are you trying to plot? Can you show your PyPlot code and any error messages you’re receiving?

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [September 13, 2018, 5:40pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/4 "2018-09-13T17:40:18Z")

</div>

I would like to plot the constraints of the mathematical model, which would be

```julia
x1 = 4
2x2 = 12
3x1 + 2x2 = 18

```

I no longer have the PyPlot code.

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [September 13, 2018, 6:16pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/5 "2018-09-13T18:16:40Z")

</div>

I don’t think there is an automatic way to print the constraints.  
I did it by hand, here is an example: [http://abelsiqueira.github.io/disciplinas/cm116/2018/Otimização.ipynb](http://abelsiqueira.github.io/disciplinas/cm116/2018/Otimiza%C3%A7%C3%A3o.ipynb)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 13, 2018, 6:20pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/6 "2018-09-13T18:20:18Z")

</div>

Something like this?

```julia
using Plots
plot([-1.5*x + 9 for x ∈ range(0,0.1,10)], label = "3x_1 + 2x_2 = 18", xlabel = "x_1", ylabel = "x_2")
vline!([4], label = "x_1 <= 4")
hline!([6], label = "x_2 <= 6")

```

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [September 13, 2018, 7:02pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/8 "2018-09-13T19:02:58Z")

</div>

Thank you!!!

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [September 13, 2018, 7:06pm UTC](https://discourse.julialang.org/t/how-to-generate-graph/14911/9 "2018-09-13T19:06:20Z")

</div>

Unfortunately I could not open the link.
