2013-03-12 55 views

回答

1

您在我的代碼中發現了一個錯誤。我有指數(data.shape)逆轉。

import matplotlib.pyplot as plt 
import numpy as np 
column_labels = list('ABC') 
row_labels = range(7) 
data = np.random.rand(7,3) 
fig, ax = plt.subplots() 
heatmap = ax.pcolor(data, cmap=plt.cm.Blues) 

# put the major ticks at the middle of each cell 
ax.set_xticks(np.arange(data.shape[1])+0.5, minor=False) 
ax.set_yticks(np.arange(data.shape[0])+0.5, minor=False) 

# want a more natural, table-like display 
ax.invert_yaxis() 
ax.xaxis.tick_top() 

ax.set_xticklabels(column_labels, minor=False) 
ax.set_yticklabels(row_labels, minor=False) 
plt.show() 

產生

enter image description here

+0

謝謝你,這是問題:) – 2013-03-20 20:44:14