Home > Software design >  I get "SyntaxError: invalid syntax" for plt.figure
I get "SyntaxError: invalid syntax" for plt.figure

Time:12-12

I am writing this program for physic class. When I tried to show the plot, I got a SyntaxError. I don't understand why.


import matplotlib.pyplot as plt
import numpy as np
import wave, sys
import scipy


ton = wave.open("A.wav", "r")


signal = ton.readframes(-1)
signal = np.frombuffer(signal, dtype ="int16") 


f_rate = ton.getframerate()


time = np.linspace(
    0, # start
    len(signal) / f_rate, #stop
    num = len(signal)


plt.figure(1)
plt.title("Sound Wave")
plt.xlabel("Time")
plt.plot(time, signal)
plt.show()


I tried to delete put.figure but that didn't help obviously

CodePudding user response:

You are not closing the bracket

time = np.linspace(
    0, # start
    len(signal) / f_rate, #stop
    num = len(signal)
)

CodePudding user response:

You forgot to close the paranthesis for this line:

time = np.linspace(
    0, # start
    len(signal) / f_rate, #stop
    num = len(signal)

To fix it:

time = np.linspace(
    0, # start
    len(signal) / f_rate, #stop
    num = len(signal)
)
  • Related