0

I am trying to plot a 3d function in python using matplotlib. For some reason I get the error "Invalid syntax (pyflakes E)" in the second line of the code provided when trying to plot it. I got this part from another person, and this works for them. The packages from matplotlib I have installed are mplot3d, cm, and Subplot. Perhaps there is another package I need?

fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(projection='3d')
1
  • 1
    Are you using Spyder? This is seemingly not a maptlotlib problem. Can you post the full traceback of the error message and include matplotlib version and how you installed it? Commented Feb 26, 2022 at 16:15

1 Answer 1

1

https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting.html#:~:text=In%C2%A0%5B3%5D%3A-,fig%20%3D%20plt.figure()%0Aax%20%3D%20plt.axes(projection%3D%273d%27),-With%20this%20three

It seems that you need to use ax = plt.axes(projection = 3d)

Sign up to request clarification or add additional context in comments.

3 Comments

The syntax of the code in the question is perfectly fine. Have you tried it?
I have not actually tried it. I guess I assumed since there is an error it won't run. It is for a neural network model. I am running the model right now, once it is done I will try and plot it and see if it works.
So I tried it and it ran. That is weird I was not expecting that. Any idea why it would be giving me a syntax error but still running?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.