EXA Fix title, overlapping plots and axis labels in plot_ols_ridge_variance.py
@@ -42,12 +42,8 @@ np.random.seed(0)
classifiers = dict(ols=linear_model.LinearRegression(),
ridge=linear_model.Ridge(alpha=.1))
-fignum = 1
for name, clf in classifiers.items():
- fig = plt.figure(fignum, figsize=(4, 3))
- plt.clf()
- plt.title(name)
- ax = plt.axes([.12, .12, .8, .8])
+ fig, ax = plt.subplots(figsize=(4, 3))
for _ in range(6):
this_X = .1 * np.random.normal(size=(2, 1)) + X_train
@@ -60,12 +56,12 @@ for name, clf in classifiers.items():
ax.plot(X_test, clf.predict(X_test), linewidth=2, color='blue')
ax.scatter(X_train, y_train, s=30, c='red', marker='+', zorder=10)
- ax.set_xticks(())
- ax.set_yticks(())
+ ax.set_title(name)
+ ax.set_xlim(0, 2)
ax.set_ylim((0, 1.6))
ax.set_xlabel('X')
ax.set_ylabel('y')
- ax.set_xlim(0, 2)
- fignum += 1
+
+ fig.tight_layout()
plt.show()
