title: Python: elegant visualisation for feasible area & objective function of LP in Matplotlib?
body: <p>I want to learn to plot the following LP problem <a href="https://stackoverflow.com/questions/30849883/linear-programming-with-scipy-optimize-linprog">here</a> elegantly with matplotlib</p>
  
  <pre><code>1*x[1] + 2x[2] -&gt; max
  
  1*x[1] + 0*x[2] &lt;= 5
  0*x[1] + 1*x[2] &lt;= 5
  1*x[1] + 0*x[2] &gt;= 1
  0*x[1] + 1*x[2] &gt;= 1
  1*x[1] + 1*x[2] &lt;= 6
  </code></pre>
  
  <p>where the first line is the objective function and the rest are the constraints of an LP problem.</p>
  
  <p>I already found a demo <a href="http://benalexkeen.com/linear-programming-with-python-and-pulp-part-1/" rel="nofollow noreferrer">here</a> that I tweaked little bit but how to do this elegantly? How to fill the upper triangle in the picture with grey with the lines (not functions like in the demo)?</p>
  
  <p><strong>How to visualise the objective function and the feasible area of a LP (linear programming) problem elegantly in Matplotlib of Python?</strong></p>
  
  <hr>
  
  <p><em>Code</em></p>
  
  <pre><code>import numpy as np, matplotlib.pyplot as plt
  #I hold x a line while defining new values for each y
  x = np.linspace(0, 20, 2000)
  #1*x[1] + 0*x[2] &lt;= 5
  #y0*0=5-x  #No initialization with respect to y0 because it is zero.
  #0*x[1] + 1*x[2] &lt;= 5
  y1=5+x*0
  #1*x[1] + 0*x[2] &gt;= 1
  #y2*0=1-x  #No inititialization
  #0*x[1] + 1*x[2] &gt;= 1
  y3=1-x*0
  #1*x[1] + 1*x[2] &lt;= 6
  y4=6-x
  #TODO: HOW TO DRAW THE ABOVE LINEAR EQUATIONS ELEGANTLY in matplotlib?
  #Drawing the lines by end points because of the zeroes.
  plt.plot(x,y4,label=r'$x[1]+x[2]&lt;=6$')
  plt.plot([5,5],[10,-10])       #x  &lt;  5
  plt.plot([10,-2],[5,5])        #y2 &lt;  5
  plt.plot([1,1],[10,-10], 'r-') #x  &gt;= 1 
  plt.plot([10,-2],[1,1],'b--')  #y3 &gt;= 1
  #TODO: how to fill the upper triangle only?
  # http://benalexkeen.com/linear-programming-with-python-and-pulp-part-1/
  #plt.fill_between(x, y5, y6, where=y5&gt;y6, color='grey', alpha=0.5)
  plt.show()
  </code></pre>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/VQkxO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VQkxO.png" alt="enter image description here"></a></p>
  </blockquote>