我想知道是否有可能在一个图形的二维表示上绘制一个竖线。假设我有一棵树,我想要与任何节点关联一个“潜力”,它可以表示为一个垂直条。
发布于 2021-02-16 21:34:51
NetworkX可以使用matplotlib绘图工具做到这一点,因为结果是matplotlib图形,您可以使用matplotlib在图表的networkx绘图之上绘制任何其他您想要的图形。
nx.draw(G)
mpl.plot([xpt, xpt], [ymin, ymax], '--b')
mpl.show()发布于 2021-02-16 22:34:08
这是一个最小的示例,它完成了我想要的(在Python中):
import networkx as nx
import random
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
degree = 3
N = 10
g = nx.random_regular_graph(degree, N)
fig = plt.figure(figsize=(10,7))
ax = Axes3D(fig)
for i,j in enumerate(g.edges()):
x = np.array((positions[j[0]][0], positions[j[1]][0]))
y = np.array((positions[j[0]][1], positions[j[1]][1]))
ax.plot(x, y, c='black', alpha=0.5)
for key, value in positions.items():
xi = value[0]
yi = value[1]
# Scatter plot
ax.scatter(xi, yi, c= 'red')
ax.bar3d(xi, yi, 0, 0.01, 0, random.random(), shade=False)
ax.set_axis_off()它生成这样的图,这对于在图上表示附加信息很有用

https://stackoverflow.com/questions/66221054
复制相似问题