简体   繁体   English

plt SyntaxError:Matplotlib 可视化中的无效语法(在 plt)

[英]plt SyntaxError: invalid syntax (at plt) in Matplotlib visualization

Here is my code,这是我的代码,

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()

You can see the "plt" alias for Matplotlib is coded as usual but the system is throwing Syntax error.Please see the error in the following,您可以看到 Matplotlib 的“plt”别名照常编码,但系统抛出语法错误。请参阅以下错误,

plt.xlim(X1.min(), X1.max())
 ^
SyntaxError: invalid syntax

This is happening wherever the plt code is used.Please share some of your valuable insights.在使用 plt 代码的任何地方都会发生这种情况。请分享您的一些宝贵见解。

The problem turned out to be very simple contrary to what I expected.结果证明这个问题非常简单,与我的预期相反。 I missed an "l" in "matplotlib."我错过了“matplotlib”中的“l”。 I coded it to be "matpotlib."我将其编码为“matpotlib”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM