SpringBoard

In [1]:
from graphPlot import *

# Define an adjacency dictionary
A = {1:[2,3], 2:[4,5], 3:[6,7]}

# Create a SpringBoard object with a field constant `Q` and spring constant `k`
SB = SpringBoard(A, k = 1, Q = -1)    

# Use `move()` to simulate the SpringBoard `deltaT` the time step, and `n` the number of timesteps:
SB.move(0.1, 500)                 

# call plot to show the image (you may have to execute the plot command twice if you are using Jupyter)
SB.plot()
<Figure size 700x700 with 1 Axes>

Since SB is an object, we can move it more:

In [2]:
SB.move(0.1, 1000)
SB.plot()

SpringBoard Animation

In [3]:
from graphPlot import *

# Define a SpringBoard object
SB = SpringBoard({1:[2, 3, 7], 2:[3, 4], 3:[5], 4:[5, 6], 5:[7, 8, 6], 6:[8, 9, 10, 11], 7:[8]}, k=1, Q=-1)

# Create an animation object
ani = SB.animate(0.1, numFrames = 100, movesPerFrame = 75, xlim = [-6.5,6.5], ylim = [-6.5,6.5], size = (7,7))

# If you are working in a Jupyter Notebook, you can use IPython to create a JS animation. Otherwise, use plt.show()
from IPython.display import HTML
HTML(ani.to_jshtml())
Out[3]:

Graph

In [4]:
from graphPlot import *

# Define an adjacency dictionary
B = {1:[2,5,4], 2:[3], 3:[6,4], 5:[7,8], 6:[7,8]}

# Define a graph object
G = Graph(B)

# call `plot()`
G.plot()

We can access the adjacency matrix of the graph G:

In [5]:
G.adjacencyMatrix
Out[5]:
array([[0, 1, 0, 1, 1, 0, 0, 0],
       [1, 0, 1, 0, 0, 0, 0, 0],
       [0, 1, 0, 1, 0, 1, 0, 0],
       [1, 0, 1, 0, 0, 0, 0, 0],
       [1, 0, 0, 0, 0, 0, 1, 1],
       [0, 0, 1, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 1, 1, 0, 0],
       [0, 0, 0, 0, 1, 1, 0, 0]])

To randomly reset the node position and have the graph "settle" again, use random_reset():

In [6]:
G.random_reset()
G.plot()

Digraph Graph

Very similarly to the pprevious example, we can create a graph object but set isDigraph to true in order to set the graph type:

In [7]:
from graphPlot import *

# Define an adjacency dictionary
C = {1: [3,2], 2: [4], 3: [5,2], 4: [2, 5, 6], 5: [7, 8, 6], 6: [8], 7: [1, 5, 8], 8: [6, 7] , 9:[6], 10:[6], 11: [6]}

# Define a graph object and set `isDigraph` to True
D = Graph(C, isDigraph = True)                       

# call plot to show
D.plot()