我有一些代码可以创建图形。但是,我不明白如何让x和y轴出现。我已经尝试过ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
,但是没有用。
我的代码
import networkx as nx
import matplotlib.pyplot as plt
Adj = np.random.randint(0,2,(5,5))
x = np.random.uniform(0,1,5)
y = np.random.uniform(0,1,5)
# convert to list of tuples
M_pos = list(zip(x,y))
# give each neuron a number, and put in a dictionary
nums = list(range(0,5))
pos_dict = dict(zip(nums,M_pos))
# construct the graph from the neuron positions and adjacency matrix
GR = nx.from_numpy_matrix(Adj, pos_dict);
figure(figsize=(10, 5))
plt.title('Neuron spatial location')
#nx.draw_networkx_labels(GR, pos_dict)
nx.draw(GR, pos_dict, node_size=40, node_color='b');
答案 0 :(得分:2)
您可以创建轴实例并传递到nx.draw
:
fig, ax = plt.subplots(figsize=(10, 5))
plt.title('Neuron spatial location')
#nx.draw_networkx_labels(GR, pos_dict)
nx.draw(GR, pos_dict, node_size=40, node_color='b', ax=ax)
# turn the axis on
ax.set_axis_on()
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
输出: