如何解决颜色条最小/最大颜色与绘制的最小/最大值不匹配
我正在绘制一个 NetworkX 图并使用加权值对边进行着色。 我正在向绘图中添加一个颜色条,并希望将颜色条的最小/最大值保持在预先确定的值上。
我的计划是迭代多次模拟并为每次迭代获得一个图表。通过这样做,我应该能够看到加权边缘颜色随时间的演变,始终与颜色栏中定义的相同(预定)最小/最大限制进行比较。
我做错了,因为在每次迭代图形中看到的边权重的最小/最大值总是与颜色条的最小/最大颜色匹配,不管边值在每次迭代中的值与颜色条最小/最大限制。
似乎在某些时候,Graph 边的 Min/Max 值和 Colorbar 的预定 Min/Max 值被置于相同的颜色级别,而 Colorbar Min/Max 值(和相关颜色)应该规则在 Graph 颜色绘制上。
提前致谢。
找到我正在运行的代码的下一部分:
图形绘制:
nx.draw(\
G,pos,# label font size
font_size = 8,# label font weight
font_weight = 'bold',# label font color
font_color = 'r',# label font familly
font_family = 'sans-serif',# node label print or not
with_labels = True,# node labels
labels = df_nodes_names['Bus Name'].to_dict(),\
# horizontalalignment ({‘center’,‘right’,‘left’}) – Horizontal alignment (default=’center’)
horizontalalignment = 'right',# verticalalignment ({‘center’,‘top’,‘bottom’,‘baseline’,‘center_baseline’})
verticalalignment = 'baseline',# node contour line width
linewidths = [2.0 if entry == 3 else 0.5 for entry in df_nodes_types.BusType],# node edge size,Confusing!!! Node contour line color,different from 'edge_color'
edgecolors = 'lightgrey',# node shape
node_shape = 'o',# node size,node_size can be scalar or array
node_size = [200 if entry == 3 else 50 for entry in df_nodes_types.BusType],# node fill color
node_color = 'whitesmoke',# # node min attribute value for lowest color in colormap palet
# vmin = df_branches_toPlot[selection_name][1],\
# # node max attribute value for highest color in colormap palet
# vmax = df_branches_toPlot[selection_name][2],\
# # node colormap deFinition
cmap = plt.set_cmap('jet'),\
# arrowstyle in directed graphs
arrowstyle="->",# arrowsize in directed graphs
arrowsize=10,# edge fill color
edge_color = df_branches_aux[selection_name],# edge width
width = 4.0,# edge colormap deFinition
edge_cmap = plt.set_cmap('jet'))
颜色条设置:
颜色条
# --------
# set Scalar Mappable for the colormar
vmin = df_branches_toPlot[selection_name][1] # minimun value for lowest color in 'cmap',read from dataframe,position [1]=min
vmax = df_branches_toPlot[selection_name][2] # maximum value for highest color in 'cmap' read from dataframe,position [2]=max
sm = plt.cm.ScalarMappable(
cmap = plt.set_cmap('jet'),\
norm = plt.normalize(vmin=vmin,vmax=vmax)
)
sm.set_array([])
cbar = plt.colorbar(
# mappable
mappable = sm,# orientation
orientation = 'vertical',# location,'orientation' and 'location' are mutually related,for this reason only one is set.
# location = 'right',# fraction,fraction of original axes to use for colorbar
fraction = 0.1,# shrink,Fraction by which to multiply the size of the colorbar.
shrink = 0.85)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。