I am trying to get my function to plot a vectorized function over a python list interval and having a name/title for the graph. I am fairly new to python packages like numpy and matplotlib. I hope someone can shed some light on my code:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def test_plot(x,interval,title):
x = np.vectorize(x)
interval = [0,interval+1]
ttl = plt.title(title)
plt.plot(x,interval)
return plt.plot(x,interval)
test_plot([-1,0,1,2,3,4],2,'test')
I get this error:
ValueError: x and y must have same first dimension
Note: I need the interval to be a list.
interval = [0,interval]Now if you run that in the Python interpreter you get something like this:interval = 2(defined in your input to the function),interval = [0,interval+1](specified in your function), which leaves your y-coordinates with only 0 and 3 to work with (check the value ofintervalin your python interpreter to verify this). The poor code can then pair only the first two elements of the x and y coordinates.vectorizeing a list?