Drawing a rectangle representing a value in python?
<p>How do I plot a rectangle with color representing a value like this picture in python? 
<a href="http://i.stack.imgur.com/OLvkW.png" rel="nofollow"><img src="http://i.stack.imgur.com/OLvkW.png" alt="enter image description here"></a> </p>

<p>I have showed a rectangle but still trying to display values in the rectangle! </p>

<pre><code>import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

fig = plt.figure()
ax = fig.add_subplot(111)
rect1 = matplotlib.patches.Rectangle((0,1), 5, 0.5, color='c')

ax.add_patch(rect1)
ax.grid()
plt.xlim([-5, 20])
plt.ylim([-5, 6])

plt.show()


someX, someY = 0.5, 0.5
plt.figure()
currentAxis = plt.gca()
currentAxis.add_patch(Rectangle((someX - .1, someY - .1), 0.2, 0.2, color = 'c', alpha=0.5))
plt.grid()
plt.show()
</code></pre>

<p>The result:
<a href="http://i.stack.imgur.com/nyhR1.png" rel="nofollow"><img src="http://i.stack.imgur.com/nyhR1.png" alt="enter image description here"></a></p>

<p>You could, for example, use the text function from matplotlib library.</p>

<p><a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text" rel="nofollow">http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text</a></p>

<p>You can also find another solution in a similar post here:</p>

<p><a href="http://stackoverflow.com/questions/14531346/how-to-add-a-text-into-a-rectangle">How to add a text into a Rectangle?</a></p>

python matplotlib