Python plt语法错误:Matplotlib可视化中的语法(在plt处)无效
这是我的密码Python plt语法错误:Matplotlib可视化中的语法(在plt处)无效,python,matplotlib,syntax,visualization,Python,Matplotlib,Syntax,Visualization,这是我的密码 import numpy as np import matplotlib.pyplot as plt import pandas as pd #Visualization from matpotlib.colors import ListedColormap X_set, y_set = X_train, y_train X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#Visualization
from matpotlib.colors import ListedColormap
X_set, y_set = X_train, y_train
X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),
np.arange(start = X_set[:, l].min() - 1, stop = X_set[:, l].max() + 1, step = 0.01))
plt.contourf(X1, X2, classifier.predict(np.array(([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
alpha = 0.75, cmap = ListedColormap(( 'red', 'green')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c = ListedColormap({'red', 'green'))(i), label = j)
plt.title('Logistic Regression (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()
您可以看到Matplotlib的“plt”别名与往常一样编码,但系统抛出语法错误。请查看以下错误:
plt.xlim(X1.min(), X1.max())
^
SyntaxError: invalid syntax
这在使用plt代码的任何地方都会发生。请分享您的一些宝贵见解。问题变得非常简单,与我的预期相反。我在“matplotlib”中漏掉了一个“l”。我将其编码为“matpotlib”。计算前一行中的括号。代码中有多个输入错误:
matpotlib
而不是matplotlib
,ListedColormap({'red',green'))
而不是ListedColormap(('red',green'))
而您在contourf
的第三个参数中遗漏了一个括号。您的问题实际上没有表现出足够的努力,或者总体上没有任何研究的迹象。我建议您重新阅读该部分。