|
23 | 23 | import matplotlib.pyplot as plt
|
24 | 24 |
|
25 | 25 | # Though the following import is not directly being used, it is required
|
26 |
| -# for 3D projection to work |
27 |
| -from mpl_toolkits.mplot3d import Axes3D |
| 26 | +# for 3D projection to work with matplotlib < 3.2 |
| 27 | +import mpl_toolkits.mplot3d # noqa: F401 |
28 | 28 |
|
29 | 29 | from sklearn.cluster import KMeans
|
30 | 30 | from sklearn import datasets
|
|
45 | 45 | titles = ["8 clusters", "3 clusters", "3 clusters, bad initialization"]
|
46 | 46 | for name, est in estimators:
|
47 | 47 | fig = plt.figure(fignum, figsize=(4, 3))
|
48 |
| - ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134) |
| 48 | + ax = fig.add_subplot(111, projection="3d", elev=48, azim=134) |
| 49 | + ax.set_position([0, 0, 0.95, 1]) |
49 | 50 | est.fit(X)
|
50 | 51 | labels = est.labels_
|
51 | 52 |
|
|
63 | 64 |
|
64 | 65 | # Plot the ground truth
|
65 | 66 | fig = plt.figure(fignum, figsize=(4, 3))
|
66 |
| -ax = Axes3D(fig, rect=[0, 0, 0.95, 1], elev=48, azim=134) |
| 67 | +ax = fig.add_subplot(111, projection="3d", elev=48, azim=134) |
| 68 | +ax.set_position([0, 0, 0.95, 1]) |
67 | 69 |
|
68 | 70 | for name, label in [("Setosa", 0), ("Versicolour", 1), ("Virginica", 2)]:
|
69 | 71 | ax.text3D(
|
|
0 commit comments