Resulta que, necesita hacer ax.add_artist(Rectangle)
para que las especificaciones de color funcionen; cuando usa patches.append(Rectangle)
, el rectángulo se muestra en azul (al menos en mi PC) ignorando cualquier especificación de color.
Por cierto, tenga en cuenta que artists — Matplotlib 1.2.1 documentation: class matplotlib.patches.Rectangle afirma que hay
edgecolor
- para el color del trazo
facecolor
- de color de relleno
... y luego está color
- que básicamente conjuntos tanto el trazo como el color de relleno al mismo tiempo.
Aquí está el código modificado OP, que he probado en Linux (Ubuntu 11.04), pitón 2.7, matplotlib 0.99.3:
import matplotlib.pyplot as plt
import matplotlib.collections as collections
import matplotlib.ticker as ticker
import matplotlib
print matplotlib.__version__ # 0.99.3
fig=plt.figure() #pylab.figure()
ax=fig.add_subplot(111)
ax.set_xlim([-400, -380]) #pylab.xlim([-400, 400])
ax.set_ylim([-400, -380]) #pylab.ylim([-400, 400])
patches = []
polygon = plt.Rectangle((-400, -400), 10, 10, color='yellow') #Rectangle((-400, -400), 10, 10, color='y')
patches.append(polygon)
pol2 = plt.Rectangle((-390, -390), 10, 10, facecolor='yellow', edgecolor='violet', linewidth=2.0)
ax.add_artist(pol2)
p = collections.PatchCollection(patches) #, cmap=matplotlib.cm.jet)
ax.add_collection(p)
ax.xaxis.set_major_locator(ticker.MultipleLocator(20)) # (MultipleLocator(20))
ax.yaxis.set_major_locator(ticker.MultipleLocator(20)) # (MultipleLocator(20))
plt.show() #pylab.show()
esta es la salida:
