I have a class POLYGON, each object of this class has as its parameters the coordinates of the vertices of the polygon (the hexagon in this case) and the parameter "value", which displays, for example, the value of a function in the hexagon. I create the required number of hexagons at given points without any problems. The question is how to draw them, so that each hexagon is colored in accordance with the value of the parameter "value" and also draw a colorbar. All this using the matplotlib library. An example of how it should turn out is in the picture.
POLYGON class:
class POLYGON: def __init__(self,xc,yc,znum,value,st): self.xc=xc #ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ° ΡΠ΅Π½ΡΡΠ° Π½Π° ΠΎΡΠΈ Π°Π±ΡΡΠΈΡΡ self.yc=yc #ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ° ΡΠ΅Π½ΡΡΠ° Π½Π° ΠΎΡΠΈ ΠΎΡΠ΄ΠΈΠ½Π°Ρ self.znum=znum #Π΄Π»Ρ Π½ΡΠΌΠ΅ΡΠ°ΡΠΈΠΈ ΠΈ ΠΏΠΎΠΈΡΠΊΠ° self.value=value #Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π² Π΄Π°Π½Π½ΠΎΠΌ ΡΠ΅ΡΡΠΈΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠ΅ self.st=st #ΡΠ°Π·ΠΌΠ΅Ρ ΠΏΠΎΠ΄ ΠΊΠ»ΡΡ self.r=st/2 #ΡΠ°Π΄ΠΈΡΡ Π²ΠΏΠΈΡΠ°Π½Π½ΠΎΠΉ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ self.R=st/pow(3,.5) #ΡΠ°Π΄ΠΈΡΡ ΠΎΠΏΠΈΡΠ°Π½Π½ΠΎΠΉ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ self.a=self.R #ΡΡΠΎΡΠΎΠ½Π° ΡΠ΅ΡΡΠΈΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠ° self.points=[(self.xc+self.a/2,self.yc+self.r), #ΠΌΠ°ΡΡΠΈΠ² ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°Ρ Π²Π΅ΡΡΠΈΠ½ (self.xc+self.R,self.yc), (self.xc+self.a/2,self.yc-self.r), (self.xc-self.a/2,self.yc-self.r), (self.xc-self.R,self.yc), (self.xc-self.a/2,self.yc+self.r)] I can draw them using pylab:
def drawPolygons (axes,points,color): """ Π ΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΌΠ½ΠΎΠ³ΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠ° """ polygon_1 = pylab.Polygon (points, facecolor=color, edgecolor='black') axes.add_patch (polygon_1) #ΠΠΎΠΏΡΡΡΠΈΠΌ, Π΅ΡΡΡ ΠΌΠ°ΡΡΠΈΠ² ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°Ρ ΡΠ΅Π½ΡΡΠΎΠ² ΡΠ΅ΡΡΠΈΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠΎΠ² xc=[0, 10.392304845413264, 20.784609690826528] yc=[0, -6.0, -12.0] poly=[] #ΠΠ°ΡΡΠΈΠ², ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠΈΠΉ ΠΎΠ±ΡΠ΅ΠΊΡΡ ΡΠ΅ΡΡΠΈΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠΎΠ² for i in range(len(xc)): #ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ ΡΠ΅ΡΡΠΈΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠ° Ρ Π΄Π°Π½Π½ΡΠΌΠΈ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌΠΈ ΡΠ΅Π½ΡΡΠ° #Π‘ΠΎ ΡΠ»ΡΡΠ°ΠΉΠ½ΡΠΌ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠΌ "value" pol=POLYGON(xc[i],yc[i],'znum',random.randint(0,20),12) poly.append(pol) pylab.xlim (-50, 50) pylab.ylim (-50, 50) axes = pylab.gca() axes.set_aspect("equal") for i in range(len(poly)): a=poly[i].points drawPolygons (axes,a,(1.0,0.0,0.0,0.7)) pylab.show() However, in this case, you have to explicitly set the color. How to make automatic generation of colors for any colormaps from matplotlib, knowing the value of "value" for all hexagons, and how to make the colorbar do not understand.

