Como faço para plotar um retângulo com cor representando um valor como esta imagem em python?
Eu mostrei um retângulo, mas ainda tentando exibir valores no retângulo!
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()
Respostas:
0 para resposta № 1Você poderia, por exemplo, usar a função de texto da biblioteca matplotlib.
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text
Você também pode encontrar outra solução em um post semelhante aqui:
Como adicionar um texto em um retângulo?