I am interested in plotting a random graph in Python.
More precisely, I consider all the points (x, y)
with integer coordinates, such that |x| < 30, |y| < 30
(n = 30 is just an example here).
Then, for each couple of points, I decide with probability p (we can say p = 0.5)
whether these two points are connected or not.
Then, I want to plot all the segments I got. For instance, we could get something like that:
The problem I encounter is that plotting all these segments takes quite some time. And of course, it increases with both n and p.
So my question is: how can I plot quickly all these segments using pyplot ?
Thank you for your help.
EDIT: here is an example of a code that works, but that is slow.
import numpy as np
import matplotlib.pyplot as plt
for i in range(101):
for j in range(101):
if i < 100:
if np.random.uniform() < 1/2:
plt.plot([i - 50, i - 50 + 1], [j - 50, j - 50], "r")
if j < 100:
if np.random.uniform() < 1/2:
plt.plot([i - 50, i - 50], [j - 50, j - 50 + 1], "r")
plt.show()