Python Forum

Full Version: matplotlib.pyplot issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I had an issue to run this code:
predicted_stock_price = model.predict(X_test)
predicted_stock_price = sc.inverse_transform(predicted_stock_price)

# Visualising the results
plt.plot(df.loc[800:, ‘Date’],dataset_test.values, color = ‘red’, label = ‘Real Price’)
plt.plot(df.loc[800:, ‘Date’],predicted_stock_price, color = ‘blue’, label = ‘Predicted Price’)
plt.xticks(np.arange(0,459,50))
The error:
Error:
plt.plot(df.loc[800:, ‘Date’],dataset_test.values, color = ‘red’, label = ‘Real Price’) ^ SyntaxError: invalid character in identifier
It seems that you are using illegal character...: Use " or ' instead.
This code works fine for me. I guess you have not used proper quotes
import matplotlib.pyplot as plt
predicted_stock_price = model.predict(X_test)
predicted_stock_price = sc.inverse_transform(predicted_stock_price)
 
# Visualising the results
plt.plot(df.loc[800:, 'Date'],dataset_test.values, color = 'red', label = 'Real Price')
plt.plot(df.loc[800:, 'Date'],predicted_stock_price, color = 'blue', label = 'Predicted Price')
plt.xticks(np.arange(0,459,50))
Here is the code and it run fine on my data and predictions.Although you can use matplotlib do make quite interactive plots.Check them out too