给定matplotlib中的一组轴,有没有办法确定其大小(以像素为单位)?我需要根据对更大或更小数字的调整来扩展事物.
(特别是我想改变线宽,使其与轴尺寸成比例.)
我有一个加权圆形布局图。我想让边缘从节点的外部开始,但找不到这样做的方法。我尝试设置 alpha=1,但这并没有给我想要的结果。下图显示了我现在得到的
这是我现在对节点的以下代码:
for n in G.nodes():
if n in set1:
G.nodes[n]['color'] = '#7a8eff'
elif n in set2:
G.nodes[n]['color'] = '#eb2c30'
elif n in set3:
G.nodes[n]['color'] = '#7300ff'
else:
G.nodes[n]['color'] = '#730a15'
colors = [node[1]['color'] for node in G.nodes(data=True)]
nx.draw_networkx_nodes(G, pos, node_size=1000, node_color=colors)
# edges
for edge in G.edges():
source, target = edge
rad = 0.25
node_color_dict = dict(G.nodes(data='color'))
if node_color_dict[source] == node_color_dict[target]:
arrowprops=dict(lw=G.edges[(source,target)]['weight'],
arrowstyle="-",
color='blue',
connectionstyle=f"arc3,rad={rad}",
linestyle= '-',
alpha=0.45)
ax.annotate("",
xy=pos[source],
xytext=pos[target],
arrowprops=arrowprops
)
else:
arrowprops=dict(lw=G.edges[(source,target)]['weight'],
arrowstyle="-",
color='purple',
connectionstyle=f"arc3,rad={rad}", …
Run Code Online (Sandbox Code Playgroud) 我正在使用 NetworkX 和 Matplotlib 绘制节点,但节点有时会在图形边缘被切断。是否有设置可以增加边距或防止它们被切断?
图像:节点在图形边缘被切除
示例程序:
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
adjacency_matrix = np.array([[1,0,0,0,0,0,1,0],[0,1,1,1,1,0,0,0],[0,1,1,0,0,0,0,0],[0,1,0,1,0,0,0,0],
[0,1,0,0,1,1,0,0],[0,0,0,0,1,1,1,1],[1,0,0,0,0,1,1,0],[0,0,0,0,0,1,0,1]])
nx_graph = nx.from_numpy_matrix(adjacency_matrix)
pos = nx.networkx.kamada_kawai_layout(nx_graph)
nx.draw_networkx_nodes(nx_graph, pos, node_color="#000000", node_size=10000)
nx.draw_networkx_edges(nx_graph, pos, color="#808080", alpha=0.2, width=2.0)
plt.axis('off')
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)