Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot x==2.5(vertical line) with sympy

Tags:

python

plot

sympy

I need to plot set of equations:

x1 + 2 * x2 == 8
x1 + 2 * x2 == 10
x1 == 5.5
x2 == 2.5

I am trying to use sympy for this:

from sympy import *
x1, x2 = symbols('x1 x2')
plot(
    solve(Eq(x1 + 2 * x2, 8), x1)[0], # x1 + 2*x2 <= 8
    solve(Eq(x1 + 2 * x2, 10), x1)[0], # x1 + 2*x2 <= 10
    5.5, # x1 <= 5.5
    Eq(x2, 2.5), # x2 <= 2.5 !<< This does not work as expected
    (x2, -2, 10)
)

Result is:

plot of three equations

It was quite easy for first three, but now I need to plot x2 == 2.5(vertical line where x2 == 2.5) and cannot get an idea how to do this.

May be sympy is not best solution here? Any other ideas for python?

like image 517
Mike Chaliy Avatar asked Oct 31 '22 22:10

Mike Chaliy


1 Answers

You can use plot_implicit.

>>> from sympy import Symbol, Eq, plot_implicit
>>> x2 = Symbol('x2')
>>> plot_implicit(Eq(x2, 2.5))

Plot

like image 189
Sudhanshu Mishra Avatar answered Nov 15 '22 03:11

Sudhanshu Mishra