相关疑难解决方法(0)

确定matplotlib轴大小(以像素为单位)

给定matplotlib中的一组,有没有办法确定其大小(以像素为单位)?我需要根据对更大或更小数字的调整来扩展事物.

(特别是我想改变线宽,使其与轴尺寸成比例.)

python matplotlib

30
推荐指数
1
解决办法
3万
查看次数

使边从 Networkx 中的节点外部开始

我有一个加权圆形布局图。我想让边缘从节点的外部开始,但找不到这样做的方法。我尝试设置 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)

python matplotlib networkx

5
推荐指数
1
解决办法
207
查看次数

如何修复使用 Matplotlib 绘制 NetworkX 图形时图形被截断的问题?

我正在使用 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)

python graph matplotlib networkx

3
推荐指数
1
解决办法
2116
查看次数

标签 统计

matplotlib ×3

python ×3

networkx ×2

graph ×1