Skip to content
Snippets Groups Projects
ex4_2_6.py 665 B
Newer Older
  • Learn to ignore specific revisions
  • bjje's avatar
    bjje committed
    # Exercise 4.2.6
    
    # requires data from exercise 4.1.1
    from ex4_2_1 import *
    
    Stas Syrota's avatar
    Stas Syrota committed
    from matplotlib.pyplot import figure, show
    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
    
    f = 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]])
    
    show()
    
    
    Stas Syrota's avatar
    Stas Syrota committed
    print("Ran Exercise 4.2.6")