Я разрабатываю код с помощью matplotlib python, чтобы показать взаимосвязь между двумя осями, и я хочу построить сумму строки на другом рисунке рядом с первым.Основная проблема в том, что я хочу сделать в другой матрице, с минимальным расстоянием относительно первой.Я прилагаю весь код решения для черчения:
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
matr=[[1,0,0],[0,0,1],[1,1,0],[0,0,1]]
def plot_tools(matrix=matr,sigma=[1,2,3,4],m=[1,2,3],name='a'):
#matrix=matrix with numbers
#sigma= values for the y axis
#m=values for the x axis
#name=name for the image
W=np.array(matrix)
id_matrix=W
id_labels=m #nombre para el eje x
fig, ax = plt.subplots()
cmap = colors.ListedColormap(['lavender','purple'])
mat = ax.imshow(id_matrix, interpolation='nearest',cmap=cmap)
plt.suptitle('Plot:')
plt.yticks(range(id_matrix.shape[0]), sigma) #label for y axis
plt.xticks(range(id_matrix.shape[1]), id_labels) #label for x axis
ax.xaxis.tick_top()
plt.xticks(rotation=0)
plt.ylabel('Y axis',fontsize=13)
plt.xlabel('X axis',fontsize=13)
major_ticks = np.arange(0, len(sigma), 1)
ax.set_yticks(major_ticks)
ax.set_yticks(major_ticks, minor=True)
temp=0
for x in xrange(id_matrix.shape[0]):
for y in xrange(id_matrix.shape[1]):
if id_matrix[x, y]==1:
temp+=1
ax.annotate(str(temp), xy=(y, x),horizontalalignment='center', verticalalignment='center')
plt.savefig('Images/' + str(name) + '.png')
plt.show()
Я бы хотел добиться следующего результата: 