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:
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?
You can use plot_implicit
.
>>> from sympy import Symbol, Eq, plot_implicit
>>> x2 = Symbol('x2')
>>> plot_implicit(Eq(x2, 2.5))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With