Skip to content
Snippets Groups Projects
ex2_3_6.py 663 B
Newer Older
  • Learn to ignore specific revisions
  • bjje's avatar
    bjje committed
    # (requires data from exercise 2.3.1)
    
    bjje's avatar
    bjje committed
    import matplotlib.pyplot as plt
    
    Stas Syrota's avatar
    Stas Syrota committed
    from mpl_toolkits.mplot3d import Axes3D
    
    bjje's avatar
    bjje committed
    
    # Indices of the variables to plot
    ind = [0, 1, 2]
    
    Stas Syrota's avatar
    Stas Syrota committed
    colors = ["blue", "green", "red"]
    
    bjje's avatar
    bjje committed
    
    
    bjje's avatar
    bjje committed
    f = plt.figure()
    
    Stas Syrota's avatar
    Stas Syrota committed
    ax = f.add_subplot(111, projection="3d")  # Here the mpl_toolkits is used
    
    bjje's avatar
    bjje committed
    for c in range(C):
    
    Stas Syrota's avatar
    Stas Syrota committed
        class_mask = y == c
        s = ax.scatter(
            X[class_mask, ind[0]], X[class_mask, ind[1]], X[class_mask, ind[2]], c=colors[c]
        )
    
    bjje's avatar
    bjje committed
    
    ax.view_init(30, 220)
    ax.set_xlabel(attributeNames[ind[0]])
    ax.set_ylabel(attributeNames[ind[1]])
    ax.set_zlabel(attributeNames[ind[2]])
    
    
    bjje's avatar
    bjje committed
    plt.show()
    
    bjje's avatar
    bjje committed