0

How do I plot a rectangle with color representing a value like this picture in python? enter image description here

I have showed a rectangle but still trying to display values in the rectangle!

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()

The result: enter image description here

vmonteco
  • 14,136
  • 15
  • 55
  • 86
Leeway
  • 143
  • 1
  • 12

1 Answers1

0

You could, for example, use the text function from matplotlib library.

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text

You can also find another solution in a similar post here:

How to add a text into a Rectangle?

Community
  • 1
  • 1
GpG
  • 502
  • 5
  • 11