2
我在python中使用matplotlib創建使用顏色條的協方差圖。但問題是ylabel繪製在彩條軸上。我無法找到如何解決這個問題。修復matplotlib中顏色條的ylabel位置
下面是一個例子:
這裏是我的代碼:
def create_covariance_plot(X, name):
"""
Visualizes the covariance matrix for a design matrix.
Parameters:
-----------
X:a design matrix where each column is a feature and each row is an observation.
name: the name of the plot.
"""
pylab.figure()
n_cols = X.shape[1]
X = X.T
R = np.corrcoef(X)
pylab.pcolor(R)
cb = pylab.colorbar()
cb.ax.set_ylabel('Correlation Strength', rotation=270)
pylab.yticks(np.arange(0, n_cols + 0.5),range(0,n_cols))
pylab.xticks(np.arange(0, n_cols + 0.5),range(0,n_cols))
pylab.xlim(0, n_cols)
pylab.ylim(0, n_cols)
pylab.xlabel("Feature")
pylab.ylabel("Feature")
pylab.savefig(name + ".png")