Run in Python3


In [3]:
import matplotlib
#matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn import datasets

%matplotlib inline

iris = datasets.load_iris()
X = iris.data
y = iris.target


fig = plt.figure()

pca = PCA(n_components=2)
print ('fitting pca')
X = pca.fit_transform(X)

markers = []
for i in y:
    if i == 0:
        markers.append('x')
    elif i == 1:
        markers.append('.')
    else:
        markers.append('D')

print ('plotting')
plt.scatter(X[:, 0], X[:, 1])
plt.show()


#ax = fig.add_subplot(111)
#ax.plot(range(100))

#fig.savefig('graph.png')


/usr/local/lib/python3.5/dist-packages/matplotlib/__init__.py:1357: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
fitting pca
plotting

In [ ]: