简体   繁体   中英

Scatter matrix for Iris data

colleagues new to Python but got a challenge to do scatter matrix for the Iris data without using a la b.

I thought a for loop can be used to plot scatter by literately one feature on another.

I have put all the features as X. Please advise what kind of mess,i have done in the code below- i am getting "x and Y must be of equal size error". How else would you do it?

for c in X:
    plt.scatter(c,X[:,0:4] )
    plt.show 

THANKS

Finally after multiple trials, this is one of the answers i managed to develop scatter matrix with histograms in the diagonal. Edits to improve the code are welcome, particularly how do i add legend to the scatter plots? thanks

fig = plt.figure( figsize=(8.5,8.5))
t= 1
for i in range (0,4):
    for j in range (0,4):
        if i==j:
            fig.add_subplot(4,4,t)
            plt.hist(X[:,i])
            plt.xlabel( feature_names[i] )
       
        else:
                    fig.add_subplot(4,4,t)
                    plt.scatter(X[:, i], X[:, j],cmap=plt.cm.Paired,c=Y, s=6)
                    plt.xlabel( feature_names[i] )
                    plt.ylabel( feature_names[j] )
                 #legend(feature_names[Y])
        t=t+1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM