RuntimeError Traceback (most recent call last) Cell In[113], line 11 8 coef1 = pd.concat([coef1,df],ignore_index=True) 9 coef1.head() ---> 11 plt.figure(figure=(9,6),dpi=600) 12 for feature in X_train.columns[:-1]: 13 plt.plot('alpha',feature,data=coef1) File c:\Users\lenovo\anaconda3\envs\python38\lib\site-packages\matplotlib\_api\deprecation.py:454, in make_keyword_only..wrapper(*args, **kwargs) 448 if len(args) > name_idx: 449 warn_deprecated( 450 since, message="Passing the %(name)s %(obj_type)s " 451 "positionally is deprecated since Matplotlib %(since)s; the " 452 "parameter will become keyword-only %(removal)s.", 453 name=name, obj_type=f"parameter of {func.__name__}()") --> 454 return func(*args, **kwargs) File c:\Users\lenovo\anaconda3\envs\python38\lib\site-packages\matplotlib\pyplot.py:840, in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs) 830 if len(allnums) == max_open_warning >= 1: 831 _api.warn_external( 832 f"More than {max_open_warning} figures have been opened. " 833 f"Figures created through the pyplot interface " (...) 837 f"Consider using `matplotlib.pyplot.close()`.", ... 755 "more than one figure") 756 self.figure = fig 757 if self.figure and self.figure is not self: RuntimeError: Can not put single artist in more than one figure Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
时间: 2023-06-19 12:05:41 浏览: 153
这个错误提示是因为您尝试将单个 artist 对象放入多个 figure 中。在这段代码中,您可能已经创建了一个 figure,并且正在尝试将同一个 artist 对象添加到另一个 figure 中。您需要检查代码中是否有重复使用同一个 artist 对象的情况,并确保每个 artist 对象只在一个 figure 中使用。如果需要在多个 figure 中显示相同的 artist 对象,您可以考虑创建多个副本。
相关问题
coef1 = pd.DataFrame() for alpha in np.linspace(0.0001,0.2,20): lasso_clf = Lasso(alpha=alpha) lasso_clf.fit(X_train[features_without_ones],y_train) df = pd.DataFrame([lasso_clf.coef_],columns=X_train[features_without_ones].columns) df['alpha'] = alpha coef1 = pd.concat([coef1,df],ignore_index=True) coef1.head() plt.figure(figure=(9,6),dpi=600) for feature in X_train.columns[:-1]: plt.plot('alpha',feature,data=coef1) plt.legend(loc='upper right') plt.xlabel(r'$\alpha$',fontsize=15) plt.ylabel("coefficient",fontsize=15) plt.show() RuntimeError: Can not put single artist in more than one figure Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
这个错误是因为您尝试将单个艺术家(Artist)放置到多个Figure中。您需要在循环外面创建一个Figure,然后在循环中使用subplot来绘制每个特征的系数。以下是修改后的代码:
```
coef1 = pd.DataFrame()
fig, ax = plt.subplots(figsize=(9,6), dpi=600)
for feature in X_train.columns[:-1]:
for alpha in np.linspace(0.0001,0.2,20):
lasso_clf = Lasso(alpha=alpha)
lasso_clf.fit(X_train[features_without_ones],y_train)
df = pd.DataFrame([lasso_clf.coef_],columns=X_train[features_without_ones].columns)
df['alpha'] = alpha
coef1 = pd.concat([coef1,df],ignore_index=True)
ax.plot('alpha',feature,data=coef1)
ax.legend(loc='upper right')
ax.set_xlabel(r'$\alpha$',fontsize=15)
ax.set_ylabel("coefficient",fontsize=15)
plt.show()
```
这个修改后的代码将循环嵌套,首先对每个特征进行循环,然后在每个特征的循环中对alpha进行循环。在每个特征的循环中,我们使用subplot来绘制每个特征的系数。
RuntimeError Traceback (most recent call last)
Can you provide more context and information about the error message? It's difficult to provide a solution without knowing the specific error message and the code that triggered it.