Description
Here we will show how to plot the following system of linear inequalities:
(1)Sage has no inequality plotting function, so we will instead plot
(2)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
Code
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()
Options
Primary Tags: Plotting: Two-dimensional plots
Secondary Tags: Two-dimensional plots: Plotting Inequalities
Tags
- Plotting a Circle
- Plotting a Polygon
- Plotting an Implicit Function
- Two-Dimensional Plots
- Parametric Plots
- Line Plots
- Plotting Two-Dimensional Vector Fields
- Multiple Plots on the Same Graph
- Controlling the Viewing Window of a Plot
- Plotting Functions with Asymptotes
- Multiple Annotation Techniques for Graphing
- Occasional Issues in Polar Plotting.
- Constructing Contour Plots in Sage
- Plotting Inequalities in Sage
- Plotting Nonlinear Inequalities in Sage
- Making log-log Plots in Sage
Related Cells
Permalink:
Author: Gregory V. Bard. Sage for Undergraduates. American Mathematical Society, Providence, RI, 2015. Available at http://www.gregorybard.com/Sage.html.
Attribute
Date: 02 Mar 2019 22:01
Submitted by: Zane Corbiere