# 1D Interacting Chain 3D Quiver Plot

```+ Tutorial 3:
1. 1D Interacting Chain
2. 1D Interacting Chain 3D Quiver Plot
3. 2D Interacting Grid```

Continuing from the previous tutorial, we start with a chain of ten particles capable of performing action P, Q or R at each time step with probability 0.2, 0.4 and 0.4 respectively. Now we place the probabilities of P, Q and R occurring into a three dimensional vector and see how it evolves over time. Initially, all vectors point in the same direction corresponding to (0.2,0.4,0.4). As network members start to interact and influence each other to perform more P, the vectors will start aligning themselves to (1,0,0) as seen in figure 1. Figure 1. The system starts off with each member having probability vector pointing in (0.2,0.4,0.4) direction and stabilizes at (1,0,0).

Known issue: matplotlib ImageMagick is used to plot the animated gif above. However, there might be issue with accessing ImageMagick. Accessing it through virtual environment, for example, had given us some error.

The code imports peripheral.py from here.

```import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D

import kero.multib.nDnet as nd
from peripheral import *

import pickle
f = open("save_folder/test_beta2.pckl","rb")
f.close()
# spt.data={
#   # Save any more data here
#   "N": N, # chain length
#   "mean_over_N": mean_over_N,
#   "interval_mean_history": interval_mean_history,
# }

# network_save_pack={
#   "network" : chain,
#   "processor" : processor,
#   "SAVEPOINT" : spt
# }

chain = network_save_pack["network"]
processor = network_save_pack["processor"]
spt = network_save_pack["SAVEPOINT"]

Tset=processor.Tset
action_history=processor.action_history
action_set = [x for x in processor.action_to_index_map] # ["P","a1","a2"]
action_index_set = [x for x in processor.index_to_action_map] # [0,1,2]
# for a,ai in zip(action_set,action_index_set):
# 	print("(action,index) = (",a,",",ai,")")
field_history = processor.field_history
Tset = processor.Tset
mean_over_N=spt.data["mean_over_N"]
interval_mean_history=spt.data["interval_mean_history"]
N=spt.data["N"]

###############################################
# Probability Quiver
###############################################
fig=plt.figure()

gallery = nd.SpecialGallery()
no_of_steps_to_animate=48
field_name_to_plot="prob"
gallery.quiver3D_lattice3D(
fig,
ax,
no_of_steps_to_animate,
chain.grid_lattice_points,
field_history,
field_name_to_plot,
field_index_to_plot=[0,1,2],
field_name_label=action_set,
grid_shape=[N,1],
time_between_steps_in_ms=100,
gif_filename='save_folder/test_beta2_quiver.gif',
show_real_time=True,
view_angle_elevation=45,
view_angle_azimuth=-60,
# xlim=[-1,4],
# ylim=[-1,4],
# zlim=[-1,4],
arrow_length_scale=0.8,
)
plt.show()```

Simulation is done using kero version: 0.5.1.