看起來就像你最自己的方式。您可以通過將軸標籤更改爲A1, A2,...
並打印其中的每個單元格的值來清理繪圖,使其更像您想要的。
腳本的清理版本低於:
import numpy as np
import matplotlib.pyplot as plt
R = np.array ([3.00, 2.50, 1.00, 3.3192, 2.383, 2.7128, 3.8662, 3.6724, 3.5112])
# Calculate the shape of the 2d array
n = int(np.sqrt(R.size))
C = R.reshape((n,n))
# Plot the matrix
plt.matshow(C,cmap="Reds")
ax = plt.gca()
# Set the plot labels
xlabels = ["B%d" % i for i in xrange(n+1)]
ylabels = ["A%d" % i for i in xrange(n+1)]
ax.set_xticklabels(xlabels)
ax.set_yticklabels(ylabels)
#Add text to the plot showing the values at that point
for i in xrange(n):
for j in xrange(n):
plt.text(j,i, C[i,j], horizontalalignment='center', verticalalignment='center')
plt.show()
而且將創建以下情節:
#2是不是代碼寫作服務 - 你嘗試過什麼等等遠? –
@SimonGibbons 我知道。 我得到了不同數組中不同列的值。 正在嘗試... –
我會建議展示您的代碼並解釋您當前被卡住的位置。這會讓我們更容易幫助你。 – cel