I have a np.array in python as below:
mat = np.array([[0.2, 0.2, 0.1, 0.1, 0.1],
[0.2, 0.2, 0.1, 0.1, 0.0],
[0.2, 0.2, 0.1, 0.1, 0.0],
[0.2, 0.1, 0.1, 0.0, 0.0]])
mat

I would like to draw lines between the same values in this array such that:

And finally I would like to have a plot like this:

I looked for a matplotlib and turtle library in python but could not find a way to plot this.
Using only matplotlib :
import matplotlib.pyplot as plt
mat = [[0.2, 0.2, 0.1, 0.1, 0.1],
[0.2, 0.2, 0.1, 0.1, 0.0],
[0.2, 0.2, 0.1, 0.1, 0.0],
[0.2, 0.1, 0.1, 0.0, 0.0]]
def line(x,y):
plt.plot(x,y,marker = 'o',color = 'red',
markerfacecolor='black',markeredgecolor='black')
def draw(mat):
for i in range(len(mat)):
for k in range(len(mat[i])-1):
if mat[i][k] == mat[i][k+1] :
line([k,k+1],[len(mat)-i,len(mat)-i])
for i in range(len(mat)-1):
for k in range(len(mat[i])):
if mat[i][k] == mat[i+1][k]:
line([k,k],[len(mat)-i,len(mat)-i-1])
draw(mat)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With