我有一个返回单个图的函数。我想重复这个函数三次,并以1x3格式并排显示3个图。我如何实现这一目标?
def plot_learning_curve(estimator, X, y, ylim=None, cv=None,
n_jobs=-1, train_sizes=np.linspace(.1, 1.0, 5)):
"""Generate a simple plot of the test and training learning curve"""
plt.figure()
plt.title(str(estimator).split('(')[0]+ " learning curves")
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Training examples")
plt.ylabel("Score")
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()
plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
train_scores_mean + train_scores_std, alpha=0.1,
color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
label="Training score")
plt.plot(train_sizes, test_scores_mean, 'o-', color="g",
label="Cross-validation score")
plt.legend(loc="best")
return plt
我已经尝试过这种方法,但它只返回一个空的1x3网格,这个空网格下面的图表
fig, axes = plt.subplots(nrows = 1, ncols = 3, sharex="all", figsize=(15,5), squeeze=False)
axes[0][0] = plot_learning_curve(tuned_clfs_vert_title2[0][0][1],Xs_train1,Y_train1,cv=skfold)
axes[0][1] = plot_learning_curve(tuned_clfs_vert_title2[0][1][1],Xs_train1,Y_train1,cv=skfold)
axes[0][2] = plot_learning_curve(tuned_clfs_vert_title2[0][2][1],Xs_train1,Y_train1,cv=skfold)
我热衷于将此学习曲线绘图功能用作“模块”。我想另一种方法是在这个函数中写一个循环。
答案 0 :(得分:0)
您没有为绘图功能提供轴。我无法使用您的代码,因为它不是Minimal, Complete, and Verifiable example。但是这里有一种方法可以满足您的需求:
publicationImages[i].set("userVote", Parse._encode(vote));
输出: