Plotting Linear Inequality Systems


Here we will show how to plot the following system of linear inequalities:

\begin{align} y &\leq 1.5 - 2x\\ y &\leq 1 - x\\ y &\leq 0.5 - 0.5x\\ x &\geq 0\\ y &\geq 0 \end{align}

Sage has no inequality plotting function, so we will instead plot

\begin{align} y &= 1.5 - 2x\\ y &= 1 - x\\ y &= 0.5 - 0.5x\\ x &= 0\\ y &= 0 \end{align}

and use the fill, fillcolor and fillalpha commands to represent the inequalities manually. When graphing $x = 0$, we will instead use $y = 10^9x$ to represent a line with a vertical slope, as the normal plot() function cannot plot $x = 0$. Other parameters set are ymin and ymax, to prevent fill from poorly adjusting the viewing window, color to provide more easily visible borders to the regions, and gridlines to increase graph readability.

Sage Cell


p1 = plot(1.5 - 2*x, (x, -0.1, 1.75), ymin=-0.25, ymax=1.75, fill=10, fillcolor='cyan', color='black', fillalpha=1/3, gridlines='minor')
p2 = plot(1 - x, (x, -0.1, 1.75), ymin=-0.25, ymax=1.75, fill=10, fillcolor='magenta', color='black', fillalpha=1/3)
p3 = plot(0.5 - 0.5*x, (x, -0.1, 1.75), ymin=-0.25, ymax=1.75, fill=-10, fillcolor='yellow', color='black', fillalpha=1/3)
p4 = plot(0, (x, -0.1, 1.75), ymin=-0.25, ymax=1.75, fill=-10, fillcolor='gray', color='black', fillalpha=1/3)
p5 = plot((10^9)*x, (x, -0.1, 1.75), ymin=-0.25, ymax=1.75, fill=10, fillcolor='gray', color='black', fillalpha=1/3)
(p1 + p2 + p3 + p4 + p5).show()


Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.


Any related cells go here. Provide a link to the page containing the information about the cell.

Related Cells


Author: Gregory V. Bard. Sage for Undergraduates. American Mathematical Society, Providence, RI, 2015. Available at


Date: 02 Mar 2019 22:01

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License