0

我想知道是否可以在图形的二维表示上绘制垂直条。假设我有一棵树,我想与任何节点关联一个可以表示为垂直条的“潜力”。

4

2 回答 2

1

This is a minimal example which does what I was looking for (in 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()

It generates this kind of plot, which can be useful to represent additional information on a graph

graph

于 2021-02-16T14:34:08.410 回答
1

NetworkX 可以使用 matplotlib 绘图工具来做到这一点,因为结果是一个 matplotlib 图形,您可以在该图形上使用 matplotlib 在图形的 networkx 图形之上绘制任何您想要的东西。

nx.draw(G)
mpl.plot([xpt, xpt], [ymin, ymax], '--b')
mpl.show()
于 2021-02-16T13:34:50.833 回答