mutational_scale我想知道关键论点的目的matplotlib;matplotlib.patches.FancyArrowPatch在用于绘制箭头的情况下,默认mutational_scale设置为。1来自文档:
标量,可选(默认值:1)
将缩放 arrowstyle 属性(例如 head_length)的值。
当我在两个大小为 300 的散点之间绘制箭头时,如下所示:
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, ax = plt.subplots()
ax.scatter([0,1],[0,1], s=300)
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>')
plt.show()
Run Code Online (Sandbox Code Playgroud)
箭头是不可见的。
但是,当我使用:
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutational_aspect=20)
Run Code Online (Sandbox Code Playgroud)
我的猜测是,整个数字按大于 1 的系数缩放,接近 20,使得箭头在突变比例为 1 时不可见,但在使用 20 时可见。但这只是一个猜测。
如果是这样,有没有办法知道整个图形的突变缩放来决定箭头的适当缩放值?
import itertools
import copy
import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
#--
edgelist = pd.read_csv('https://gist.githubusercontent.com/brooksandrew /e570c38bcc72a8d102422f2af836513b/raw/89c76b2563dbc0e88384719a35cba0dfc04cd522/edgelist_sleeping_giant.csv')
edgelist.head(10)
#--
nodelist = pd.read_csv('https://gist.githubusercontent.com/brooksandrew/f989e10af17fb4c85b11409fea47895b/raw/a3a8da0fa5b094f1ca9d82e1642b384889ae16e8/nodelist_sleeping_giant.csv')
nodelist.head(5)
#--
g = nx.Graph()
#--
for i, elrow in edgelist.iterrows():
g.add_edge(elrow[0], elrow[1], attr_dict=elrow[2:].to_dict())
#--
#print(elrow[0])
#print(elrow[1])
#print(elrow[2:].to_dict())
#--
g.edges(data=True)[0:5]
g.nodes(data=True)[0:10]
#--
print(format(g.number_of_edges()))
print(format(g.number_of_nodes()))
Run Code Online (Sandbox Code Playgroud)
得到我以下错误:
Traceback (most recent call last):
File "C:/Users/####/Main.py", line 22, in <module>
g.edges(data=True)[0:5]
TypeError: 'EdgeDataView' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
除了娜达,我还读了其他几篇文章。从我的简单理解来看,错误是由错误引起的,[0:5]但我很可能是错误的。
我是一个相当基础的编码人员,正在尝试按照本教程进行操作,但出现了以上错误。