Quick Inquiry

# Graphing Inequalities in python ?

Sympy does provide `plot_implicit`, which is a good starting point in the sense that it shows the filled area represented by the overall inequality. However, it is hardly good enough to show the limiting curves, which the OP has explicitely asked about. Since the OP doesn't mind the libraries being used, I'm going to use the which is an overall improvement to what SymPy is currently offering (disclamair: I am the developer of this module. Hopefully one day it will be part of SymPy).

Here is an example:

``` ```from sympy import var
from spb import * # SymPy Plotting Module
var("x, y")

c = 3
# a boolean expression composed of multiple inequalities
expr = (y < x + c) & (y < -x + c) & (y > x - c) & (y > -x - c)

# assuming y is on the LHS of the inequality, here we extract
# the RHS, which are going to create the limiting lines
expressions = []
for a in expr.args:
rhs = a.args[1]
# append to expression the tuple (RHS, label)
expressions.append((rhs, str(a)))

# plot the limiting lines
p1 = plot(*expressions, (x, -5, 5), aspect="equal",
line_kw={"linestyle": "--"})
# plot the region represented by the overall expression
p2 = plot_implicit(expr, (x, -5, 5), (y, -5, 5))
# combine the plots
(p1 + p2).show()``````

### Write a Comments

* Be the first to Make Comment