'AxesSubplot' object has no attribute 'tranAxes'
时间: 2023-08-02 13:05:36 浏览: 38
根据您提供的代码,出现了错误提示 "'AxesSubplot' object has no attribute 'tranAxes'"。这是因为在 `ax.text()` 函数中,您使用了 `ax.tranAxes`,但是正确的属性名称是 `ax.transAxes`。
请将 `ax.tranAxes` 修改为 `ax.transAxes`,以修正这个错误。以下是修正后的代码片段:
```python
import numpy as np
for ds_cnt, (x, y) in enumerate(datasets):
ax = axes[ds_cnt, 0]
if ds_cnt == 0:
ax.set_title("Input data")
ax.scatter(x[:, 0], x[:, 1], c=y, zorder=10, cmap=plt.cm.Paired, edgecolors="k")
ax.set_xticks(())
ax.set_yticks(())
for est_idx, kernel in enumerate(kernel):
ax = axes[ds_cnt, est_idx + 1]
clf = svm.SVC(kernel=kernel, gamma=2).fit(x, y)
score = clf.score(x, y)
ax.scatter(x[:, 0], x[:, 1], c=y, zorder=10, cmap=plt.cm.Paired, edgecolors="k")
ax.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=50, facecolors="none", zorder=10, edgecolors="k")
x_min, x_max = x[:, 0].min() - .5, x[:, 0].max() + .5
y_min, y_max = x[:, 1].min() - .5, x[:, 1].max() + .5
if ds_cnt == 0:
ax.set_title('kernel')
ax.text(0.95, 0.6, ('%.2f' % score).lstrip('0'), size=15,
bbox=dict(boxstyle='round', alpha=.8, facecolor='white', transform=ax.transAxes,
horizontalalignment='right'))
plt.tight_layout()
plt.show()
```
这样修改后,应该能够解决错误并正确显示图形。如果还有其他问题,请随时提问。