def diff_graph(self, show=False, printout=True):
"""Plot a 2D map with nodes and weights difference among neighbouring nodes.
Args:
show (bool, optional): Choose to display the plot.
printout (bool, optional): Choose to save the plot to a file.
"""
neighbours=[]
for node in self.nodeList:
nodelist=[]
for nodet in self.nodeList:
if node != nodet and node.get_nodeDistance(nodet) <= 1.001:
nodelist.append(nodet)
neighbours.append(nodelist)
diffs = []
for node, neighbours in zip(self.nodeList, neighbours):
diff=0
for nb in neighbours:
diff=diff+node.get_distance(nb.weights)
diffs.append(diff)
centers = [[node.pos[0],node.pos[1]] for node in self.nodeList]
widthP=100
dpi=72
xInch = self.netWidth*widthP/dpi
yInch = self.netHeight*widthP/dpi
fig=plt.figure(figsize=(xInch, yInch), dpi=dpi)
ax = hx.plot_hex(fig, centers, diffs)
ax.set_title('Nodes Grid w Weights Difference', size=80)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.0)
cbar=plt.colorbar(ax.collections[0], cax=cax)
cbar.set_label('Weights Difference', size=80, labelpad=50)
cbar.ax.tick_params(labelsize=60)
plt.sca(ax)
printName='nodesDifference.png'
if printout==True:
plt.savefig(printName, bbox_inches='tight', dpi=dpi)
if show==True:
plt.show()
if show!=False and printout!=False:
plt.clf()
评论列表
文章目录