I'm trying to display a graph with a formula from the user using matplotlib in Python 3.6, but I'm having some problems. I tried
import numpy as np
import matplotlib.pyplot as plt
def graph(x_range):
x = np.array(x_range)
y = 2*x
plt.plot(x, y)
plt.show()
graph(range(-10, 11))
which works fine, but if I try replacing y = 2*x
with y = input()
and try inputting 2*x
in the terminal, I get an error stating ValueError: Illegal format string "2*x"; two marker symbols
Any ideas as to how to fix this error, or is there a better way to graph a equation given by the user?
Thanks