1

I have some code that creates a graph. However, I don't understand how to let the x and y axes appear. I have tried ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True) but it doesn't work.

My code

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');

Steve
  • 353
  • 3
  • 12
  • 1
    You should define the ax parameter in nx.draw I think, I'll give it a shot when I have time a bit later. – Mathieu Sep 30 '19 at 18:43

1 Answers1

7

You can create an axis instance and pass to 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)

Output:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74